zcydanzcy
zcydanzcy
2016-08-17 01:10
采纳率: 100%
浏览 3.2k
已采纳

从一个APP打开别人的APP ,提示 not exported from uid

注意:我是用自己的APP打开**别人的APP**。我遇到的问题是自己的APP不能打开手机里面已经装好的QQ阅读。我不能修改QQ阅读的任何代码,所以"exported ="true"“可能不适用于我这个情况。在此感谢所有愿意为我这个问题花时间的大大。

下面是错误提示:**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

下面是我启动别人APP的代码

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();
}
}         
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • FFZ2009
    FFZ2009 2016-08-17 02:25
    已采纳

    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<ResolveInfo> 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();
        }
    }
    
    
    
    点赞 评论

相关推荐