Rotary Heart
Rotary Heart

Reputation: 1969

How to open specific third party activity?

Ok I want to open a specific Activity from a app, not my app. Let's say that I want to open this package com.test.app and inside that package TestActivity. How can I do this?

I have tried like this:

Intent i = new Intent();
i.setClassName(pack, activity);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(i);

Intent i = new Intent(pack+activity);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(i);

Intent i = new Intent();
i.setClassName(pack, "."+activity);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(i);

Intent i = new Intent(pack+"."+activity);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(i);

With all of them I'm having this error:

Unable to find explicit activity class {PACKAGE/ACTIVITY}; have your declared this activity in your AndroidManifest.xml?

NOTE: I do have the app installed with package com.test.app and with an activity TestActivity. So how could this be done?

Upvotes: 3

Views: 1253

Answers (4)

Vinit Khanna
Vinit Khanna

Reputation: 81

I think you might have not declared the new java class in manifest file. If not then open your manifest file, open ANdroidmanifest.xml and inside the tag below tag write this

Upvotes: 0

balaji koduri
balaji koduri

Reputation: 1321

check the 3rd party application is installed in your device or emulator, then only it will gives the proper result.

Upvotes: 0

user1571055
user1571055

Reputation: 369

do u try below code?

Intent i = new Intent();// if TestActivity has an action. please add by yourself
i.setClassName("com.test.app", "com.test.app.TestActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);// maybe no use here
getApplicationContext().startActivity(i);

Upvotes: 0

Brian Attwell
Brian Attwell

Reputation: 9299

First, you must make sure that the target activity is exported. It must be exported explicitly with android:export="true", or implicitly, with an intent-filter. You can't send an Intent to any random Activity of any app.

Upvotes: 2

Related Questions