how to find my android application's storing path of apk file

↘锁芯ラ 提交于 2019-11-29 17:13:31

There is no need to iteration. Getting the application itself APK file uri is as easy as this:

String appUri = getApplicationInfo().publicSourceDir;

Also note that doc says this about publicSourceDir:

Full path to the publicly available parts of sourceDir, including resources and manifest. This may be different from sourceDir if an application is forward locked.

And also note that to send an APK file, you need to set the type to application/vnd.android.package-archive instead of image/*

So the complete snippet would be:

String appUri = getApplicationInfo().publicSourceDir;
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("application/vnd.android.package-archive");
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(appUri)));
startActivity(Intent.createChooser(sharingIntent, "Share via"));

finally i'd found the right answer that works in this purpose, thanks to @Kanak for her help :)

PackageManager pm = getPackageManager();
    String uri = null;
    for (ApplicationInfo app : pm.getInstalledApplications(0)) {
        if(!((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1))
            if(!((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1)){
                uri=app.sourceDir;
                  if(uri.contains("com.example.test"))
                  break;
            }
    }

    Intent intent = new Intent();  
    intent.setAction(Intent.ACTION_SEND);  
    intent.setType("image/*");
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(uri)));
    startActivity(intent);
List<ApplicationInfo> 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

So, this way you will find path of all apps apk.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!