Reputation: 6912
I have write 2 app, A_app and B_app.
In A_app, I want to call B_app and launch B_app's CalledActivity.
But the B_app's MAINActivity is MainActiity not CalledActivity.
In A_app, I try below code to call B_app:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.example.bapp","com.example.bapp.BActivity"));
intent.putExtra ("test2abc", "abctest2");
startActivity(intent);
And in B_app's BActivity has code in onCreate as below:
Bundle params = getIntent().getExtras();
if (params != null) {
String temp = params.getString ("test2abc");
Toast.makeText (BActivity.this, temp, Toast.LENGTH_LONG).show();
}
But there are some error as below:
01-10 10:47:16.904: E/AndroidRuntime(8355): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cmp=com.example.bapp/.BActivity (has extras) } from ProcessRecord{418a3788 8355:com.dlink.nas/u0a7} (pid=8355, uid=10007) not exported from uid 10115
I want the B_app is only called directly by A_app without other call it.
How can I fixed it?
Upvotes: 0
Views: 78
Reputation: 36449
You need to add this to the "B_app" Android Manifest under BActivity
's <activity>
node:
android:exported="true"
So it looks something like:
<activity android:name=".Bactivity"
android:label="@string/b_activity"
android:exported="true">
<!--rest of activity node -->
</activity>
Another way to "export" is by setting an intent-filter (also in manifest):
<intent-filter>
<action android:name="myFilter" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Since Android does not allow access to all Activities by default, just the main one.
To answer your edited question, there is a way to allow apps to call each other's components without exporting, as shown in this SO answer. You have to add the sharedUserLabel
and sharedUserId
attributes in the manifest. However, they note that it is not recommended, since it can cause slight changes in operation.
Upvotes: 2