Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to detect whether the apk is stored on SD-card or not?

Tags:

android

Is there a way to detect whether the apk is stored on SD-card or not? How?

like image 566
user1074896 Avatar asked Jan 03 '12 12:01

user1074896


2 Answers

Use getApplicationInfo().sourceDir

http://developer.android.com/reference/android/content/pm/ApplicationInfo.html

like image 173
avepr Avatar answered Oct 01 '22 18:10

avepr


To make the accepted answer more concrete, here's an example of how I've used it in the context of accessing files written to internal vs external storage, according to API level 7 guidelines or lower:

{   //...
    mInternalApp = context.getApplicationInfo().sourceDir.matches("^/data/app/.*");
    mPathInternal = context.getApplicationInfo().dataDir + "/files/";
    mPathExternal = Environment.getExternalStorageDirectory() + "/Android/data/"
                + PACKAGE_NAME + "/files/";
}

private File getMyFile() {
    return (mInternalApp) ? new File(mPathInternal + INT_FILE_NAME) :
                            new File(mPathExternal + EXT_FILE_NAME);
}
like image 42
qix Avatar answered Oct 01 '22 18:10

qix