Reputation: 379
I want to determine whether a installed application is a system application or not.
So I have got a list of installed applications like this:
And want to change the background colour of all applications, which are system applications.
Here is the corresponding part of my code:
private void kindElementTexte () {
// TODO: Bildericons sollen angezeigt werden
ActivityManager manager =
( ActivityManager ) this.getSystemService ( ACTIVITY_SERVICE );
ArrayList< String > kinder = new ArrayList< String > ();
final PackageManager pm = getPackageManager ();
List< ApplicationInfo > packages = pm.getInstalledApplications ( PackageManager.GET_META_DATA );
View inflate = getLayoutInflater(). inflate(R. layout. anwendung_starten_layout, null);
String packetName = null;
for ( ApplicationInfo packageInfo : packages ) {
packetName = packageInfo.packageName;
kinder.add ( packetName );
}
kindElemente.add ( kinder );
}
Is there a opportunity to do that?
Thanks a lot.
Upvotes: 0
Views: 329
Reputation: 12725
In the for-loop, check whether the app is a system app or not and adjust the color as needed.
You can check system apps with the following code:
for ( ApplicationInfo packageInfo : packages ) {
if ((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
//is system app
}
}
Read more about different flags in the ApplicationInfo documentation.
Upvotes: 2
Reputation: 1168
I think this is a valid solution and displays all system apps for me:
for (ApplicationInfo packageInfo : packages) {
if ((packageInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
System.out.println(packageInfo.packageName + "is a system application");
}
}
Upvotes: 1