I'm new in android, I need to open an existing app when click button in my app, how can I do that? Is there need the app's package name? if need, how to get the name. Thanks.
Asked
Active
Viewed 710 times
1 Answers
3
You can try :
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.example.package", "com.example.package.ActivityToStart");
startActivity(intent);
or
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.example.package");
startActivity(intent);
If you don't know the package name of installed app in your device, then you can try this to get a list of package :
PackageManager pm = getPackageManager();
//get a list of installed apps.
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
Log.d(TAG, "Installed package :" + packageInfo.packageName);
Log.d(TAG, "Source dir : " + packageInfo.sourceDir);
Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName));
}
Piyush Kukadiya
- 1,925
- 15
- 26