Reputation: 509
I am using following code to differentiate between User Installed App and System App:
final PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages)
{
if ((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0)
Log.d(TAG, "Installed package (System) :" + packageInfo.packageName);
else
Log.d(TAG, "Installed package (User) :" + packageInfo.packageName);
}
How ever this gives some apps as User Installed Apps which are actually not. Following is the LogCat in my emulator:
Installed package (User) :com.android.smoketest
Installed package (User) :com.android.widgetpreview
Installed package (User) :com.example.android.livecubes
Installed package (User) :com.example.android.apis
Installed package (User) :com.android.gesture.builder
Installed package (User) :com.example.android.softkeyboard
Installed package (User) :com.android.smoketest.tests
Installed package (User) :faheem.start
Ideally, only last application should be output in User Installed Apps.
Upvotes: 3
Views: 7210
Reputation: 880
Uddhav Gautam
I think your answer is wrong in multiple places.
the code you site in the link specifically states:
/** * Flags associated with the application. Any combination of
which means your third example (following the OR) is completely wrong since the value 0x1001 has the 1 bit set but is definitely not equal to 1
that said I do agree that the correct way to test for any bit being set is:
if ((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM) == ApplicationInfo.FLAG_SYSTEM)
Upvotes: 1