Siddharth Mishra
Siddharth Mishra

Reputation: 59

Intents to link to another app

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

Answers (4)

vishal jangid
vishal jangid

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

Abx
Abx

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

Tran Vinh Quang
Tran Vinh Quang

Reputation: 595

Try this:

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(launchIntent);

Upvotes: 1

Ajit Pratap Singh
Ajit Pratap Singh

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

Related Questions