I have Two Applications AppOne & AppTwo
App Two has activity as the following:
<activity android:name=".AppTwoActivity">
<intent-filter>
<action android:name="com.myAction.TestAction"></action>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
What I should do to lunch AppTwoActivity from AppOne (Different App)?
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Intent
Intent intent = new Intent();
startActivity(intent);
}
});
CodePudding user response:
Add the below code to the manifest of your App One. Replace the name with your second apps package name.
<queries>
<package android:name="second.app.package.name" />
</queries>
Then launch that activity using the code below. Or you can use @CommonsWare answer too.
Intent intent = new Intent();
intent.setClassName("second.app.package.name", "second.app.package.name.ActivityName");
startActivity(intent);
CodePudding user response:
Use an Intent
that will resolve to the other app's activity:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// Intent
Intent intent = new Intent("com.myAction.TestAction");
try {
startActivity(intent);
} catch (Throwable t) {
Log.e("AppOne", "Exception starting AppTwo", t);
// TODO something to let the user know that the other app is not installed or we otherwise cannot start the activity
}
}
});