如果我想从我的应用程序启动其他应用程序,那么我可以编写以下代码。
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);
但在我的方案中,我不想打开其他应用程序的启动器Activity
,我想打开其他特定的Activity
。
有人可以帮助我吗?
答案 0 :(得分:0)
我想打开其他特定活动
要从包而不是启动器启动其他活动,请使用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);
答案 1 :(得分:0)
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";
然后调用此
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();
}