How to Check If an App Is a Non-System App in Android

How do I check if an app is a non-system app in Android?

Well, it's a sloppy solution in my opinion (what if /data/app isn't the apps directory on all devices?), but after a thorough search, this is what I have come up with:

for (ApplicationInfo ai : appInfo) {
if (ai.sourceDir.startsWith("/data/app/")) {
//Non-system app
}
else {
//System app
}
}

How to get the list of all non system apps in android

If an Application is a non-system application it must have a launch Intent by which it can be launched. If the launch intent is null then its a system App.

Example of System Apps: "com.android.browser.provider", "com.google.android.voicesearch".

For the above apps you will get NULL when you query for launch Intent.

PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for(ApplicationInfo packageInfo:packages){
if( pm.getLaunchIntentForPackage(packageInfo.packageName) != null ){
String currAppName = pm.getApplicationLabel(packageInfo).toString();
//This app is a non-system app
}
else{
//System App
}
}

How can I dynamically detect whether my application is system or normal?

You could try using the flags available in the ApplicationInfo class (android.conent.pm). For example:

...
PackageManager pm = getPackageManager();
List<ApplicationInfo> installedApps = pm.getInstalledApplications(0);

for (ApplicationInfo ai: installedApps) {

if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
// System app - do something here
...
} else {
// User installed app?
}
}

Check if app belongs to system apps or to apps signed with platform key

Actually, ApplicationInfo.FLAG_SYSTEM and ApplicationInfo.FLAG_UPDATED_SYSTEM_APP flags do work, but they were tested against the wrong flags. Here is the correct code:

val applicationInfo = packageManager.getApplicationInfo(packageName, 0)
val isSystem =
(applicationInfo.flags and ApplicationInfo.FLAG_SYSTEM != 0) ||
(applicationInfo.flags and ApplicationInfo.FLAG_UPDATED_SYSTEM_APP != 0)

android get only user install app not system apps

Just use this:

List<ApplicationInfo> apps = getPackageManager().getInstalledApplications(0);
for(ApplicationInfo app : apps) {
if((app.flags & (ApplicationInfo.FLAG_UPDATED_SYSTEM_APP | ApplicationInfo.FLAG_SYSTEM)) > 0) {
// It is a system app
} else {
// It is installed by the user
}
}

You can make a separate array and then add user installed apps in this form the else statement. Such as:

else {
// It is installed by the user
UserAppArray<ApplicationInfo>.add(app);
}

How to check programmatically if an application is installed or not in Android?

Try with this:

public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Add respective layout
setContentView(R.layout.main_activity);

// Use package name which we want to check
boolean isAppInstalled = appInstalledOrNot("com.check.application");

if(isAppInstalled) {
//This intent will help you to launch if the package is already installed
Intent LaunchIntent = getPackageManager()
.getLaunchIntentForPackage("com.check.application");
startActivity(LaunchIntent);

Log.i("SampleLog", "Application is already installed.");
} else {
// Do whatever we want to do if application not installed
// For example, Redirect to play store

Log.i("SampleLog", "Application is not currently installed.");
}
}

private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
}

return false;
}

}

How can I get a list of apps installed, but not including system apps?

Hi you can use the code below

 for(ApplicationInfo app : apps) {
//checks for flags; if flagged, check if updated system app
if((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1) {
installedApps.add(app);
//it's a system app, not interested
} else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
//Discard this one
//in this case, it should be a user-installed app
} else {
installedApps.add(app);
}
}


Related Topics



Leave a reply



Submit