zcydanzcy
zcydanzcy
2016-08-16 09:40
采纳率: 100%
浏览 6.1k
已采纳

从一个APP打开另一个APP ,提示 not exported from uid

Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.qq.reader/.widget.picbrowser.PictureActivity } from ProcessRecord{3823559b 16851:com.pax.market.android.app/u0a322} (pid=16851, uid=10322) not exported from uid 10324

  public static void openApp(Activity activity,String packageName) {
PackageInfo pi;
try {
    pi = activity.getPackageManager().getPackageInfo(packageName, 0);
    Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
    resolveIntent.setPackage(pi.packageName);
    PackageManager pManager = activity.getPackageManager();
    List apps = pManager.queryIntentActivities(
            resolveIntent, 0);

    ResolveInfo ri = (ResolveInfo) apps.iterator().next();
    if (ri != null) {
        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);
        activity.startActivity(intent);
    }
} catch (NameNotFoundException e) {
    Log.e(TAG, "Package Name not found: " + e.getMessage() + ", App is not installed.");
} catch (SecurityException e){
    SnackBar.newBuilder().activity(activity).
            text(activity.getString(R.string.permission_denied_to_open))
            .build().show();
}

}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

5条回答 默认 最新

  • zcydanzcy
    zcydanzcy 2016-08-17 03:18
    已采纳

    List apps = pManager.queryIntentActivities(resolveIntent, 0);查询出的符合条件的activity是有可能是多个的。
    对于com.qq.reader来说可查询出两个:
    com.qq.reader.widget.picbrowser.PictureActivity
    com.qq.reader.activity.SplashActivity
    其中PictureActivity是不能被启动的,因为它的exported=false,但是SplashActivity是可以启动的。
    代码修改了一下,是可以启动qqreader的,是从SpalshActivity启动的。

    public static void openApp(Activity activity,String packageName) {
    PackageInfo pi;
    try {
    pi = activity.getPackageManager().getPackageInfo(packageName, 0);
    Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
    resolveIntent.setPackage(pi.packageName);
    PackageManager pManager = activity.getPackageManager();
    List apps = pManager.queryIntentActivities(
    resolveIntent, 0);
    for(ResolveInfo app: apps){

            Log.d(TAG,String.format("%s %s",app.activityInfo.packageName,app.activityInfo.name));
            packageName = app.activityInfo.packageName;
            String className = app.activityInfo.name;
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            ComponentName cn = new ComponentName(packageName, className);
            intent.setComponent(cn);
            try {
                activity.startActivity(intent);
            }catch(SecurityException e){
                e.printStackTrace();
            }
        }
      /*  ResolveInfo ri = (ResolveInfo) apps.iterator().next();
        if (ri != null) {
            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);
            activity.startActivity(intent);
        }*/
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Package Name not found: " + e.getMessage() + ", App is not installed.");
    } catch (SecurityException e){
        SnackBar.newBuilder().activity(activity).
                text(activity.getString(R.string.permission_denied_to_open))
                .build().show();
    }
    

    }

    点赞 评论
  • zhanggang740
    JackWaiting 2016-08-16 09:48

    意思是你的手机没有安装这个包名,这种情况应该跳转到你手机有的应用市场下载此应用

    点赞 评论
  • Android_Technology
    逆刘而上Plus 2016-08-16 11:03

    manifest.xml里面定义了同名的activity 造成程序不能启动。
    这个Activity在Manifest文件里写了两份,去掉一份后,就可以正常运行了。

    点赞 评论
  • shensky711
    HansChen_ 2016-08-16 12:59

    com.qq.reader/.widget.picbrowser.PictureActivity,确定这个activity是添加了android:exported="true"属性?,看提示是目标activity没设置exported

    点赞 评论
  • qq_37028558
    qq_37028558 2017-08-03 02:01

    楼主在吗,我也遇到这样的问题,能不能给我个完整的例子看看,你这个openapp这个方法的参数填的是什么/

    点赞 评论

相关推荐