首先要知道你要打开apk文件的包名。
可以使用包名查看器查看。百度搜索:android包名查看器
得到包名然后调用以下方法,把包名传入进去就行了。。。
代码:
public void invokingApk(String packageName){
//实例化PackageManager
PackageManager packageManager = this.getPackageManager();
Intent localIntent = new Intent("android.intent.action.MAIN", null);
localIntent.addCategory("android.intent.category.LAUNCHER");
Iterator<ResolveInfo> it1 = packageManager.queryIntentActivities(localIntent, 0).iterator();
//遍历包名
while (it1.hasNext()) {
ResolveInfo resolveInfo = it1.next();
//如果相等,就执行以下程序
if (!packageName.equals(resolveInfo.activityInfo.applicationInfo.packageName))
continue;
ComponentName componentName = new ComponentName(resolveInfo.activityInfo.applicationInfo.packageName,
resolveInfo.activityInfo.name);
localIntent.setComponent(componentName);
//localIntent.addFlags(268435456);
this.startActivity(localIntent);//跳转到apk
}
}