How to get package name from apk in Android?

后端 未结 3 972
长情又很酷
长情又很酷 2021-01-29 08:42

I am developing an app which will contain a list of Apps. On click the user will be redirected to the Play Store to download this app. On successful download I have to send that

3条回答
  •  不知归路
    2021-01-29 09:19

    You can get all installed app in device using below code

    final PackageManager pm = getPackageManager();
    //get a list of installed apps.
    List packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
    
    for (ApplicationInfo packageInfo : packages) {
        Log.d(TAG, "Installed package :" + packageInfo.packageName);
        Log.d(TAG, "Source dir : " + packageInfo.sourceDir);
        Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); 
    }
    

    and find package name in for loop.

提交回复
热议问题