Reputation: 59
I have recently developed my second app. On clicking a specific button, I wish to open my first app. How do I do this?
I do know that I have to use Uri.parse, but how exactly do I use it?
Upvotes: 1
Views: 193
Reputation: 3025
if you want to open the other application you should know the package name of the launching app. try below code .
try {
Intent intent = context.getPackageManager().getLaunchIntentForPackage("pakage name of application which you want to launch");
if (intent ! = null) {
intent.addCategory(Intent.CATEGORY_LAUNCHER);
context.startActivity(intent);
}
} catch (PackageManager.NameNotFoundException e) {
}
Upvotes: 0
Reputation: 2882
Try this SO question Open another application from your own (intent) found the below answer good enough
public static boolean openApp(Context context, String packageName) {
PackageManager manager = context.getPackageManager();
try {
Intent i = manager.getLaunchIntentForPackage(packageName);
if (i == null) {
return false;
//throw new PackageManager.NameNotFoundException();
}
i.addCategory(Intent.CATEGORY_LAUNCHER);
context.startActivity(i);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
Upvotes: 0
Reputation: 595
Try this:
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(launchIntent);
Upvotes: 1
Reputation: 1289
You will have to create an intent for that.As you know the package name you can create an intent as below and call startActivity
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("package.name");
startActivity(launchIntent);
Upvotes: 1