How to jump to APP by package name in android 11 and above

The following is the code to jump to other APPs through the package name, taking the WeChat APP package name as an example:

val intent : Intent?
        intent = activity?.packageManager?.getLaunchIntentForPackage("com.tencent.mm")
        if (intent == null) {
            Log.d("Alex", "intent = $intent")
        } else {
            startActivity(intent)
        }

According to the log, the intent is null. When the package name is wrong or the app is not configured to start the Activity, it will be null. Why?

After a night of searching online, I found the answer, as follows:

Below Android 11, the above code can be redirected, but for Android 11 and above, the methods related to querying package names are restricted.

Method 1 : You must configure permissions in the AndroidManifest.xml file, as follows:

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

Method 2 : You must configure the package name of the jump app in the AndroidManifest.xml file, as follows:

<queries >
    <package android:name="com.tencent.mm"/>
</queries>

pls:

In the Android12 version system, Google has further restricted the QUERY_ALL_PACKAGES permission. When the application uses the four interfaces of getAllPermissionGroups(), getPermissionGroupInfo(), getPermissionInfo() and queryPermissionsByGroup(), the application must apply for this permission to access valid data. The above four interfaces are to obtain the collection of all permission groups, to obtain permission group information according to the specified permission group name, to obtain permission information according to the specified permission, and to query permission according to the permission group.

At the same time, in the Android 12 version system, the application can declare and create a custom Activity, which allows the user to manage the data stored by the application on the user's device after the Activity is started. The prerequisite for the application to use the Activity is that it must have both the MANAGE_EXTERNAL_STORAGE permission and the QUERY_ALL_PACKAGES permission.

Well, you can play happily again.

Some common APP package names:

// WeChat package name com.tencent.mm //Startup class name: com.tencent.mm.ui.LauncherUI

 //QQ package name com.tencent.mobileqq //Start class name: com.tencent.mobileqq.activity.HomeActivity

//Alipay package name: com.eg.android.AlipayGphone //Start class name com.eg.android.AlipayGphone.FastStartActivity

// DingTalk package name: com.alibaba.android.rimet // Startup class name: com.alibaba.android.rimet.biz.home.activity.HomeActivity

//QQ zone package name: com.qzone

//QQ mobile housekeeper package name: com.tencent.qqpimsecure

//Weibo package name: com.sina.weibo //Start class name: com.sina.weibo.EditActivity

//Tiantiandongting package name: com.sds.android.ttpod

// Chinese perpetual calendar package name: cn.etouch.ecalendar

//Baidu map package name: com.baidu.BaiduMap

//AutoNavi map package name: com.autonavi.minimap //Startup class name: com.autonavi.map.activity.SplashActivity

//Information package name: com.android.mms

//Set the package name: com.android.settings

//Browser package name: com.android.browser

//Calculator package name: com.android.calculator2

//Clock package name: com.android.deskclock

//Gallery package name: com.android.gallery3d

//Camera package name: com.android.hwcamera

//Music package name: com.android.mediacenter

//Radio package name: com.huawei.android.FMRadio

//Recorder package name: com.android.soundrecorder

//UC browser package name: com.UCMobile

// Meitu Xiuxiu package name: com.mt.mtxx.mtxx

//PPTV package name: com.pplive.androidphone

//Shuqi free novel package name: com.shuqi.controller

//360 mobile assistant package name: com.qihoo.appstore

//360 guard package name: com.qihoo360.mobilesafe

//360 cleaning master package name: com.qihoo.cleandroid_cn

//Baidu mobile assistant package name: com.baidu.appsearch

// Pea pod package name: com.wandoujia.phoenix2

//Mi app store package name: com.xiaomi.market

//Huawei app store package name: com.huawei.appmarket

//Anzhi application store package name: com.hiapk.marketpho

//RE manager package name: com.speedsoftware.rootexplorer 

//PP mobile assistant package name: com.pp.assistant

//OPPO app store package name: com.oppo.market

//Lenovo App Store package name: com.lenovo.leos.appstore

//Application package name: com.tencent.android.qqdownloader

Guess you like

Origin blog.csdn.net/msn465780/article/details/131692627