简体   繁体   中英

(Android) Find path /Android in internal storage

Is there a method in Android that returns the data path on internal storage?

I have 2 Android smartphone (Samsung s2 and s7 edge) where i installed an application. I want to take a sqliteDB situated in this path:

/Android/data/application.most/files/most_db

The problem is that in Samsung s2 i must use this path to take the DB:

private static final String db_path = "/storage/sdcard0/Android/data/org.application/files/application_db";

Instaed, in s7 i must use this:

private static final String db_path = "/storage/emulated/0/Android/data/application.most/files/application_db";

I want to take this path independently by device.

Can you help me?

Thanks in advance.

我认为你所寻找的是那样的东西

String path = getFilesDir().getAbsolutePath();

Basically you want to Access Applications External Directory. ie. "sdcard/Android/data/yourPackage/files"

You should use: getExternalFilesDir(null) method of Context Class.

private static final String db_path = getExternalFilesDir(null).getAbsolutePath() + "/application_db";

OR you can Directly get File Instance like:

File file = new File(getExternalFileDir(null),"application_db");

Make Sure you add WRITE_EXTERNAL_STORAGE Permission in the Manifest.

You can read more about this at : https://developer.android.com/reference/android/content/Context.html#getExternalFilesDir(java.lang.String)

Once change your Logic in different versions.. till android 4.xx it take internal memory as /storage/sdcard0/ where as from 4.4 kitKat it will take path as /storage/emulated/0/

Design multiple apk depending on android API versions...

your problem is solved.. you can install it in s2 with that path and S7 with this path...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM