[英]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.