android在一个应用中启中另外一个应用


String packageName = tempPkInfo.activityInfo.packageName;


一般都不知道应用程序的启动Activity的类名,而只知道包名,我们可以通过ResolveInfo类来取得启动Acitivty的类名。

private void openApp(String packageName) {

PackageInfo pi = getPackageManager().getPackageInfo(packageName, 0);

Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
resolveIntent.setPackage(pi.packageName);

List<ResolveInfo> apps = pm.queryIntentActivities(resolveIntent, 0);

ResolveInfo ri = apps.iterator().next();
if (ri != null ) {
String packageName = ri.activityInfo.packageName;
String className = ri.activityInfo.name;

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);

ComponentName cn = new ComponentName(packageName, className);

intent.setComponent(cn);
startActivity(intent);
}
}
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页