1 <?xml version="1.0" encoding="utf-8"?> 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="com.example.metrox.codepermission"> 4 5 <permission android:name="com.example.metrox.codepermission.permission.SAY_HELLO" /> 6 <permission android:name="com.example.metrox.codepermission.permission.myAty" /> 7 <uses-permission android:name="com.example.metrox.codepermission.permission.SAY_HELLO" /> 8 9 <application 10 android:allowBackup="true" 11 android:icon="@mipmap/ic_launcher" 12 android:label="组件权限分配" 13 android:supportsRtl="true" 14 android:theme="@style/AppTheme"> 15 <activity android:name=".MainActivity"> 16 <intent-filter> 17 <action android:name="android.intent.action.MAIN" /> 18 19 <category android:name="android.intent.category.LAUNCHER" /> 20 </intent-filter> 21 </activity> 22 <activity android:name=".myAty" 23 android:label="被启动的Activity" 24 android:permission="com.example.metrox.codepermission.permission.myAty"> 25 <intent-filter> 26 <category android:name="android.intent.category.DEFAULT"></category> 27 <action android:name="com.example.metrox.codepermission.intent.action.myAty"></action> 28 </intent-filter> 29 </activity> 30 </application> 31 32 </manifest>
1 <?xml version="1.0" encoding="utf-8"?> 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="com.example.thesecend"> 4 <uses-permission android:name="com.example.metrox.codepermission.permission.myAty"></uses-permission> 5 <application 6 android:allowBackup="true" 7 android:icon="@mipmap/ic_launcher" 8 android:label="@string/app_name" 9 android:supportsRtl="true" 10 android:theme="@style/AppTheme"> 11 <activity android:name=".MainActivity"> 12 <intent-filter> 13 <action android:name="android.intent.action.MAIN" /> 14 15 <category android:name="android.intent.category.LAUNCHER" /> 16 </intent-filter> 17 </activity> 18 </application> 19 20 </manifest>
1 package com.example.thesecend; 2 3 import android.content.Intent; 4 import android.support.v7.app.AppCompatActivity; 5 import android.os.Bundle; 6 import android.view.View; 7 8 public class MainActivity extends AppCompatActivity { 9 10 @Override 11 protected void onCreate(Bundle savedInstanceState) { 12 super.onCreate(savedInstanceState); 13 setContentView(R.layout.activity_main); 14 findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { 15 @Override 16 public void onClick(View view) { 17 startActivity(new Intent("com.example.metrox.codepermission.intent.action.myAty")); 18 } 19 }); 20 } 21 }
时间: 2024-10-05 04:45:04