简体   繁体   English

Android:如何从我们的应用程序启动其他应用程序的特定活动?

[英]Android : How to launch specific Activity of other apps from our app?

If I want to launch other applications from my application then I can write the following code. 如果我想从我的应用程序启动其他应用程序,那么我可以编写以下代码。

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

But in my scenario, I don't want to open the launcher Activity of other application and I want to open other specific Activity . 但在我的场景中,我不想打开其他应用程序的启动器Activity ,我想打开其他特定的Activity

Could someone help me? 有人能帮助我吗?

I want to open other specific Activity 我想打开其他特定的Activity

To launch other Activity from package instead of launcher use PackageInfo.activities to gell all activities declared in AndroidManifest.xml : 要从包而不是启动器启动其他Activity,请使用PackageInfo.activities来解决在AndroidManifest.xml声明的所有活动:

PackageManager pm = getPackageManager();
PackageInfo packageInfo = pm.getPackageInfo("com.package.address", 0);
ActivityInfo[] activitiesInfos = packageInfo.activities;
ActivityInfo activityToLaunch=activitiesInfos[0]; //<< activity which want to start

// Create ComponentName object using packageName and activity name
ComponentName compName=new ComponentName(
                                     activityToLaunch.applicationInfo.packageName,
                                     activityToLaunch.name);
Intent intent=new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(compName);
startActivity(intent);
private static final String _PACKAGE_NAME = "app package name which you want to open";
private static final String _CLASS_NAME = _PACKAGE_NAME + ".activity class which you want to access";

and then call this 然后调用它

    try {
                Intent intent = new Intent();
                intent.setClassName(_PACKAGE_NAME, _CLASS_NAME);
                // Set your data in my case i have url 
                intent.setData(Uri.parse(playlistUrl));
                // If "package" extra is set, app will be able to show your app name as a title
                intent.putExtra("package", getPackageName());
               startActivity(intent);

            } catch (ActivityNotFoundException e) {
                // app is not installed, let's ask the user to install it.
               AppNotFoundDialog();
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从URL启动Android应用程序的特定活动? - How to launch specific activity of the android app from url? 启动具有特定活动的Android应用 - Launch Android App with Specific Activity 从我的应用程序中调用(启动)其他应用程序(如whatsapp)所需的权限是什么 - What are permissions required to call(launch) other apps like whatsapp in my case from our app 如何从其他应用程序启动我的 Flutter 应用程序 - How can I Launch My Flutter App from other Apps 如何以编程方式限制一个应用程序或监视android中其他应用程序的活动? - How to restrict an app or monitor other apps activity in android programatically? 从Android Service类启动其他活动后如何关闭1个活动 - How to close 1 Activity after the Launch of other from Android Service Class 如何从我们的Android应用程序删除其他应用程序缓存? - How to delete other applications cache from our android app? 如何在最近的应用程序菜单上按“我的应用程序”图标启动特定活动 - How to Launch specific activity on press My App icon on recent apps menu 如何从Android App启动其他Android App? - How to launch other Android App from Android App? 从后台启动具有特定活动的应用 - launch app with specific activity from background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM