Android Get Application's 'Home' Data Directory

Android Get Application's 'Home' Data Directory

Of course, never fails. Found the solution about a minute after posting the above question... solution for those that may have had the same issue:

ContextWrapper.getFilesDir()

Found here.

Get Application Directory

PackageManager m = getPackageManager();
String s = getPackageName();
PackageInfo p = m.getPackageInfo(s, 0);
s = p.applicationInfo.dataDir;

If eclipse worries about an uncaught NameNotFoundException, you can use:

PackageManager m = getPackageManager();
String s = getPackageName();
try {
PackageInfo p = m.getPackageInfo(s, 0);
s = p.applicationInfo.dataDir;
} catch (PackageManager.NameNotFoundException e) {
Log.w("yourtag", "Error Package name not found ", e);
}

How can I get the external application data path in android?

simply use Context.getExternalCacheDir(), this is the standard way android provides for external cache, when your app uninstalled, the dir removed automatically and don' t leave any trash for the user.

the dir pattern ends like Android/data/your-package-name/cache/

but you should check null for the return value (a File object), if null, it indicates that the cache dir is not avaialbe(like sd card removed or connected to your pc, etc.)

How to access data/data folder in Android device?

Accessing the files directly on your phone is difficult, but you may be able to copy them to your computer where you can do anything you want with it.
Without rooting you have 2 options:

  1. If the application is debuggable you can use the run-as command in adb shell

    adb shell
    run-as com.your.packagename
    cp /data/data/com.your.packagename/
  2. Alternatively you can use Android's backup function.

    adb backup -noapk com.your.packagename

    You will now be prompted to 'unlock your device and confirm the backup operation'. It's best NOT to provide a password, otherwise it becomes more difficult to read the data. Just click on 'backup my data'. The resulting 'backup.ab' file on your computer contains all application data in android backup format. Basically it's a compressed tar file. This page explains how you can use OpenSSL's zlib command to uncompress it.
    You can use the adb restore backup.db command to restore the backup.

Get access to data directory for private data storage

You cannot get access to this directory from "outside" (only if it's a rooted device). From your app you have permission to access to this folder by default (both read and write). Just call the getFilesDir() to access to the folder.
http://developer.android.com/reference/android/content/ContextWrapper.html#getFilesDir()



Related Topics



Leave a reply



Submit