How to find application storage location programmatically in android

I want to find if the application is installed on external storage or on internal storage? This line only repeats the application path:

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

Thank you in advance

For example, I want:

Skype internal storage

+4
source share
4 answers

I did like this:

 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"; } } 
+1
source

This will give you a list of application files (.apk) installed on your device -

 adb shell pm list packages -f 

Some of my device lists are

 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 

List of installed packages containing the term myapp -

adb shell pm list packages | grep myapp

Cmd output:

package: com.myapp.main

Show myapp application installation myapp -

adb shell pm path com.myapp.main

Cmd output:

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

NOTE. If your application uses internal storage, it will create a unique folder accessible only from your application. No other application can see what's in it. However, external repositories are similar to shared folders.

Applications on the SD card more info ..

+1
source

Package List = 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); } 
0
source

Android: INSTALLLOCATION = "internalOnly"

Android: INSTALLLOCATION = "preferExternal"

Android: INSTALLLOCATION = "Auto"

-2
source

Source: https://habr.com/ru/post/1489036/


All Articles