Android跳轉到第三方APP(QQ,微信,QQ音樂,酷狗音樂)
阿新 • • 發佈:2019-02-08
/** * 檢查已安裝的應用程式。並開啟 */ private void openApp(){ //應用過濾條件 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); PackageManager mPackageManager = mContext.getPackageManager(); 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; // 開啟酷狗音樂APP if(pkg.contains("com.kugou.android")){ ComponentName componet = new ComponentName(pkg, cls); Intent intent = new Intent(); intent.setComponent(componet); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(intent); } } }