To implement this function, two applications a and B must have corresponding permissions to access an activity in.
1. First, let's look at the implementation of.
First add a textview to activity A, and write some content for convenience. Set manifest. xml below to add a custom permission
Code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="giuz.blog1"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="giuz.blog1.ActivityBlog1"
android:label="@string/app_name"
android:permission="giuz.permission.SEE">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<permission android:protectionLevel="normal" android:name="giuz.permission.SEE">
</permission>
</manifest>
Note the underline section.
The first underline indicates that the Android: name of the activity requires package name + class name: giuz. blog1.activityblog1. Otherwise, the activity cannot be found.
<Permission Android: protectionlevel = "normal" Android: Name = "giuz. Permission. See"> </permission>This sentence,
Android: protectionlevel is required. Its value is normal or dangerous, signature, signatureorsystem.
Android: the value of name is a custom permission in the format of **. Permission. ** (giuz. X. Permission. See is also acceptable ).
2. B's implementation
B's activity is accessed through intent. In my code, the following code is included in the Click Event of a button:
Intent intent = new intent ();
// The following is implemented using component:
// If I write intent. setclassname ("giuz. blog1", "giuz. blog1.activityblog1 ")
// But an error is reported.
Intent. setcomponent (New componentname ("giuz. blog1", "giuz. blog1.activityblog1 "));
Startactivity (intent)
The first parameter in the second row is the package name of the accessed activity of a, and the second parameter is the package name + class name.
Because A has the custom permission, and B does not have the permission to access it now, if you access it now, the permission denial error will occur.
Add the following statement to manifest. xml of B.
<uses-permission android:name="giuz.permission.SEE"></uses-permission>
In this way, B has access permissions.
Paste two running sheets