Android getting running apps using FLAG ApplicationInfo.FLAG_STOPPED is not working

533 Views Asked by At

I'm facing trouble with MiUi SO when I run the following function.

fun getAppsThatCanBeStopped(context: Context): List<String> {
    return with(ArrayList<String>()) {
        addAll(
            context.packageManager.getInstalledApplications(PackageManager.GET_META_DATA)
                .filter { (it.flags and ApplicationInfo.FLAG_STOPPED == 0) and (it.flags and ApplicationInfo.FLAG_SYSTEM == 0) }
                .map { it.packageName }
        )
        this@with
    }
}

The problem is only with MiUi SO all the apps are returning, The FLAG ApplicationInfo.FLAG_STOPPED it's not being satisfied.
Should return only the apps that aren't stopped and aren't system apps.

Any suggestions?

0

There are 0 best solutions below