如何在android中以编程方式查找应用程序的存储位置

时间:2013-07-01 07:34:35

标签: android

我想知道应用程序是安装在外部存储还是内部存储上?此行仅重新启动应用程序的路径:

String path = p.getApplicationInfo(info.packageName, 0).sourceDir;

提前致谢

例如我想要这个:

Skype内部存储

4 个答案:

答案 0 :(得分:1)

这将为您提供设备上安装的应用程序(.apk)文件列表 -

adb shell pm list packages -f

我的部分设备列表

package:/system/framework/framework-res.apk=android
package:/system/app/MusicPickerActivity.apk=com.MusicPickerActivity
package:/system/app/Kindle.apk=com.amazon.kindle
package:/system/app/BackupRestoreConfirmation.apk=com.android.backupconfirm
package:/system/app/Browser.apk=com.android.browser
package:/system/app/Calculator.apk=com.android.calculator2
package:/system/app/Calendar.apk=com.android.calendar
package:/system/app/CertInstaller.apk=com.android.certinstaller
package:/system/app/ChromeWithBrowser.apk=com.android.chrome
package:/system/app/Contacts.apk=com.android.contacts
package:/system/app/DefaultContainerService.apk=com.android.defcontainer
package:/system/app/DeskClock.apk=com.android.deskclock
package:/system/app/Email.apk=com.android.email

列出包含术语myapp -

的已安装软件包
  

adb shell pm list packages | grep myapp

cmd输出:

  

包:com.myapp.main

显示应用程序myapp -

的安装目录
  

adb shell pm path com.myapp.main

cmd输出:

  

包:/data/app/com.myapp.main-2.apk

注意:如果您的应用程序使用内部存储,那么它将创建一个只能从您的应用程序访问的唯一文件夹。没有其他应用程序可以看到其中的内容。但是,外部存储就像公共文件夹。

Applications on SD card详细信息..

答案 1 :(得分:0)

List packs = packageManager.getInstalledPackages(0); //PackageManager.GET_META_DATA

  for(int i=0; i < packs.size(); i++) {

     PackageInfo p = packs.get(i);
     ApplicationInfo a = p.applicationInfo; 
     // skip system apps if they shall not be included
     if ((!includeSysApps) && ((a.flags & ApplicationInfo.FLAG_SYSTEM) == 1)) {
        continue;
     }
     App app = new App();
     app.setTitle(p.applicationInfo.loadLabel(packageManager).toString());
     app.setPackageName(p.packageName);
     app.setVersionName(p.versionName);
     app.setVersionCode(p.versionCode);
     CharSequence description = p.applicationInfo.loadDescription(packageManager);
     app.setDescription(description != null ? description.toString() : "");
     apps.add(app);

  }

答案 2 :(得分:0)

我这样做了:

List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo appInfo : packages)
{
   String storage = null;
   String appStorage = applicationStorage(appInfo);
   if(appStorage.startsWith("/data/"))
   {
      storage = "Internal";
   }
   else
   {
      storage = "SD Card";
   }
}

答案 3 :(得分:-3)

机器人:的installLocation = “internalOnly”

机器人:的installLocation = “preferExternal”

机器人:的installLocation = “自动”