How to get the file *.apk location in Android device

前端 未结 5 2001
小蘑菇
小蘑菇 2020-11-30 04:22

Need some help by retrieving *.apk file name from Android device programmaticaly ? Could any body provide some Android methods doing that or even shell commands run under An

5条回答
  •  北海茫月
    2020-11-30 04:56

    List PackageManager.getInstalledApplications() will give you a list of the installed applications, and ApplicationInfo.sourceDir is the path to the .apk file.

    PackageManager pm = getPackageManager();
    
    for (ApplicationInfo app : pm.getInstalledApplications(0)) {
      Log.d("PackageList", "package: " + app.packageName + ", sourceDir: " + app.sourceDir);
    }
    

    Outputs something like this:

    package: com.tmobile.themechooser, sourceDir: /system/app/ThemeChooser.apk
    package: com.tmobile.thememanager, sourceDir: /system/app/ThemeManager.apk
    package: com.touchtype.swiftkey, sourceDir: /data/app/com.touchtype.swiftkey-1.apk
    package: com.twitter.android, sourceDir: /data/app/com.twitter.android-2.apk
    package: fm.last.android, sourceDir: /data/app/fm.last.android-1.apk
    

提交回复
热议问题