简体   繁体   中英

How to redirect to another app from a button in android?

我想使用一个按钮从我的实际应用程序重定向到另一个应用程序,没有重定向到另一个活动,我引用了另一个应用程序,但是我只看到了在同一应用程序中重定向到另一个活动的答案,这在两个应用程序之间有帮助?

this is only valid if you know the package name of another app...

    String packageName = "packagename_of_other_app";
    Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
    if(intent != null) {
        startActivity(intent);
    }

You need to raise a intent, try like this:

Uri mUri = Uri.parse("market://details?id=" + packageName);
Intent mIntent = new Intent(Intent.ACTION_VIEW, mUri);
startActivity(marketIntent);

Where packageName would be package name of your another app.

The notion of an "app" is not well-defined. To start the launch activity of a package:

PackageManager manager = getPackageManager();
Intent intent = manager.getLaunchIntentForPackage("com.my_co.my_app");
intent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(intent);

I've omitted exception and null handling in the above.

Hi we may need the package name for this purpose

 String packageName = "com.musetheplace.rssfeed.activity";
    Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
    if(intent != null) {
        startActivity(intent);
    }

or what you can do is

Uri mUri = Uri.parse("market://details?id=" + "com.musetheplace.rssfeed.activity");
Intent mIntent = new Intent(Intent.ACTION_VIEW, mUri);
startActivity(mIntent );

You can create a custom action in another app. for example

           <intent-filter>
                <action android:name="android.intent.action.run" />
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>

Then, in you app, you just need to use this action string

                Intent intent = new Intent("android.intent.action.run");
                startActivity(intent);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM