android 应用程序打开另一个apk

来源:互联网 发布:新西兰网络攻略 编辑:程序博客网 时间:2024/06/05 15:07

首先要知道你要打开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    }}


原创粉丝点击