开发者

Is my app in /system?

My application can be installed and run on android,

in two different plac开发者_高级运维es:

"/data/MyApplication"  

and

"/system/MyApplication".

I need to know where at the moment is my application installed,

if it is in "/data/" or if it is in "/system".

Can anyone help?

Thank you very much


Obtain where your application is installed by

getPackageManager().getApplicationInfo(getPackageName(), 0).sourceDir

however this should not be important for your application. Why do you need it ?


Please don't hard-code checks to directory paths.

You can find out of your app is part of the built-in system image with ApplicationInfo.FLAG_SYSTEM. But as the other poster says, there should be few reasons to need to do this... and note that if a newer version of your app is installed from Market on a device that has it bundled, FLAG_SYSTEM will still be set since it is still effectively a system app.


You can use adb to find out:

$ adb shell ls /data

or

$ adb shell ls /system

Or do you want this check at runtime from within your application. In that case you could use

System.getProperty("user.dir")

in your Java code.


Please use the below hard code to found the location of user installed application path either in /data or /system:

PackageInfo paramPackageInfo = null;
        try {
            paramPackageInfo = getPackageManager().getPackageInfo(
                    getPackageName(), 0);
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }

ApplicationInfo localApplicationInfo = paramPackageInfo.applicationInfo;

To found package name : localApplicationInfo.packageName

To found application path : localApplicationInfo.sourceDir


I would recommend use package manager tool for that. adb shell pm path your.package.name

Sample of usage:

#List all installed packages
$ adb shell pm list packages
package:com.android.soundrecorder
....
package:com.android.email           # <-- System app
....
package:course.labs.intentslab.test # <-- Custom app

#Path for system app:
$ adb shell pm path com.android.email
package:/system/app/Email.apk

#Path for regular app:
$ adb shell pm path course.labs.intentslab.test
package:/data/app/course.labs.intentslab.test-1.apk

From documentation:

path PACKAGE Print the path to the APK of the given PACKAGE

Using package manager (pm)

Some info on Android StackOverflow

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜