I am developing an app that uses packagenames to start a Third Party App. I have done some research and found out that all apps can be started from a launcher intent. Are there anyone that knows how to do this from a click of a Button.
Asked
Active
Viewed 6,432 times
1
-
Duplicate http://stackoverflow.com/questions/3422758/start-application-knowing-package-name – Calvin Mar 17 '12 at 18:31
-
This is not a duplication. I ask how to start it and that question is how to find the packagename. I already know how to find the package name. – Magakahn Mar 17 '12 at 18:34
3 Answers
6
You can't really 'start applications'. You can try to get the Launch Intent from the 3rd party application if you know the packagename:
Intent intent = getPackageManager().getLaunchIntentForPackage("com.thirdparty.package");
startActivity( intent );

Johannes Staehlin
- 3,680
- 7
- 36
- 50
-
1One should set the flags to "setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)" to reopen already opened apps. – JacksOnF1re Feb 24 '16 at 13:56
5
For above accepted answer, if the third party app is not installed on your emulator, you should gracefully handle it also. Here is a complete code for the same:
public void openThirdPartyApp() {
Intent intent = new Intent("com.thirdparty.package");
intent.setPackage("com.thirdparty.package");
try {
((Activity) context).startActivityForResult(intent, REQUEST_CODE);
} catch (ActivityNotFoundException e) {
downloadIt();
}
}
private void downloadIt() {
Uri uri = Uri.parse("market://search?q=pname:" + "com.thirdparty.package");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
try {
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
//creates a small window to notify there is no app available
}
}
}
}

YuDroid
- 1,599
- 5
- 22
- 44
-
Good answear but this does not work with what I am doing. I am using a packagemanager that gets the package name and then start it. But this may be useful in later projects. Thanks for the answear! – Magakahn May 13 '12 at 10:46
-
This doesn't work... In the intent initialization code: Intent intent = new Intent("com.thirdparty.package"); there should be an action like "android.intent.action.MAIN" no? – syonip Dec 16 '15 at 12:05
-
-
According to the docs, an Intent constructor with a string argument, needs to receive and action, not a package name. http://developer.android.com/reference/android/content/Intent.html – syonip Dec 16 '15 at 13:16
2
Just put it in an View.OnClickListener:
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = getPackageManager().getLaunchIntentForPackage(theOtherActivityPackage);
startActivity( intent );
}
});

MByD
- 135,866
- 28
- 264
- 277