问题
I have an app which has an activity and activity-alias. I am trying to call this activity from another app through activity-alias but it crashes when i add permission in activity-alias. If no permission is added, it works fine.
<permission
android:name="com.USE_SASETTINGS"
android:protectionLevel="normal" />
<activity android:name=".DemoActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity-alias
android:name=".demoAlias"
android:exported="true"
android:targetActivity="DemoActivity"
android:permission="com.USE_SASETTINGS">
<intent-filter>
<action android:name="com.example.accountsettingone"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity-alias>
From another app, i am trying to call the activity through activity-alias.
Manifest of another app:
<uses-permission android:name="com.USE_SASETTINGS"/>
Activity of another app:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent();
startActivity(new Intent("com.example.accountsettingone"));
}
}
But application crashes. Error message:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.testpermissionsingleactiivty, PID: 24625
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testpermissionsingleactiivty/com.example.testpermissionsingleactiivty.MainActivity}: java.lang.SecurityException: Permission Denial: starting Intent { act=com.example.accountsettingone cmp=com.example.app.test/com.example.app.test.demoAlias } from ProcessRecord{9b35008 24625:com.example.testpermissionsingleactiivty/u0a187} (pid=24625, uid=10187) requires com.USE_SASETTINGS
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3610)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3756)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2246)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8037)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=com.example.accountsettingone cmp=com.example.app.test/com.example.app.test.demoAlias } from ProcessRecord{9b35008 24625:com.example.testpermissionsingleactiivty/u0a187} (pid=24625, uid=10187) requires com.USE_SASETTINGS
at android.os.Parcel.createException(Parcel.java:2088)
at android.os.Parcel.readException(Parcel.java:2056)
at android.os.Parcel.readException(Parcel.java:2004)
at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:4469)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1716)
at android.app.Activity.startActivityForResult(Activity.java:5258)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)
at android.app.Activity.startActivityForResult(Activity.java:5203)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:663)
at android.app.Activity.startActivity(Activity.java:5587)
at android.app.Activity.startActivity(Activity.java:5555)
at com.example.testpermissionsingleactiivty.MainActivity.onCreate(MainActivity.java:16)
at android.app.Activity.performCreate(Activity.java:7963)
at android.app.Activity.performCreate(Activity.java:7952)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3585)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3756)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2246)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8037)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.wm.ActivityStackSupervisor.checkStartAnyActivityPermission(ActivityStackSupervisor.java:1401)
at com.android.server.wm.ActivityStarter.startActivity(ActivityStarter.java:936)
at com.android.server.wm.ActivityStarter.startActivity(ActivityStarter.java:716)
at com.android.server.wm.ActivityStarter.startActivityMayWait(ActivityStarter.java:2004)
at com.android.server.wm.ActivityStarter.execute(ActivityStarter.java:630)
I am newbie. Eagerly waiting for feedback.
来源:https://stackoverflow.com/questions/65889015/how-to-start-activity-alias-of-another-app-which-has-permission