android在应用内如何打开第三方应用?QQ应用程序

private void openApp(String str){  
        //应用过滤条件  
        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);  
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);  
        System.out.println("testrrr");  
        PackageManager mPackageManager = mContext.getPackageManager();  
        System.out.println("tesr");
        List<ResolveInfo> mAllApps = mPackageManager.queryIntentActivities(mainIntent, 0);  
        //按报名排序  
        Collections.sort(mAllApps, new ResolveInfo.DisplayNameComparator(mPackageManager));  
  
        for(ResolveInfo res : mAllApps){  
            //该应用的包名和主Activity  
            String pkg = res.activityInfo.packageName;  
            String cls = res.activityInfo.name;  
            System.out.println("pkg---" +pkg);  
           // System.out.println("打印出来的----" + str);  
  
            // 打开QQ pkg中包含"qq",打开微信,pkg中包含"mm"  
            if(pkg.contains(str)){  
                ComponentName componet = new ComponentName(pkg, cls);  
                Intent intent = new Intent();  
                intent.setComponent(componet);  
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
                mContext.startActivity(intent);  
            }  
        }
 }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容