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:
If the application is debuggable you can use the
run-as
command in adb shelladb shell
run-as com.your.packagename
cp /data/data/com.your.packagename/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 theadb 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
Android Active Link of Url in Textview
Supporting Amazon and Android Market (Google Play) Links Inside Application
How to Create a Persistent Alarmmanager
Is Google-Services.JSON Safe from Hackers
What Is The Different Between Explicit and Implicit Activity Call in Android
Firebase Android Onauthstatechanged Called Twice
Reasons That The Passed Intent Would Be Null in Onstartcommand
List View Item Swipe Left and Swipe Right
Make Android Webview Not Store Cookies or Passwords
Remove Animation/Shifting Mode from Bottomnavigationview Android
Android How to Wait Until a Service Is Actually Connected
How to Store Files Generated from App in "Downloads" Folder of Android
How to Disable Viewpager Adapter on Touching Specific Views
Gradle Android Build for Different Processor Architectures
When Should I Do Certain Sqlite Operations on Another Thread(Not The Main Thread)