0

How to launch other Android App from Android App if I have got the package name of App?

For example: I create a Button in an Android App. When press the Button , the Skype will launch.

  1. Is it possible to do the above action in Android?
  2. Is it should use Intent to launch other App when Button has been click?
  3. What permission does it need?

Thanks in advance.

4

5 Answers 5

2

Yes if You have other app package name

Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("other app package name");
startActivity(LaunchIntent);
1

Since it's not your app, as you mentioned, "Skype". You can use the app's package ID in intent.

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

For Skype, it becomes,

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.skype.raider");
startActivity(launchIntent);

In your Java file, say MainActivity.java

    Button button = (Button) findViewById(R.id.button);

    button.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {

    Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.skype.raider");
    startActivity(launchIntent);
                }
            });

And in layout file, say activity_main.xml

 <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Skype →"
        android:id="@+id/button"
        android:textColor="@color/white"/>
1

You can use following code to launch skype or any other app:

PackageManager packageManager = getPackageManager();
Intent intent = packageManager.getLaunchIntentForPackage("<skype_package_name>");
startActivity(intent);
0

Try this code:

PackageManager pm = context.getPackageManager();
try {
    if (pm.getApplicationInfo("com.your.package.name", 0) == null) {
        // no talk, no update
        Toast.makeText(context, "packagenot found", Toast.LENGTH_SHORT).show();

    } else {
        Intent packageIntent= pm.getLaunchIntentForPackage("com.your.package.name");

        packageIntent.addCategory(Intent.ACTION_SENDTO);
        packageIntent.setType("text/plain");
        startActivity(packageIntent);
    }
} catch (PackageManager.NameNotFoundException e) {

    // no talk, no update
    Toast.makeText(context, "Package not found", Toast.LENGTH_SHORT).show();
}
0
    final String appPackageName = "com.example";
                        final Intent openPlayStore = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName));
                        if (hasHandlerForIntent(openPlayStore))
                            startActivity(openPlayStore);
                        else
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));

private boolean hasHandlerForIntent(Intent intent) {
        return getActivity().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.