1

In my application I want check if application on device or not!
I write below codes, below android 11 it's work and not any problem! but above android 11 not check if this application installed or not!
My codes :

public static Intent openAppWithPackage(Context context, String packageName) {
    Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
    return launchIntent;
}

How can I fix it in android 11+ ?

Dr.KeyOk
  • 608
  • 1
  • 6
  • 13
  • 1
    Check this thread https://stackoverflow.com/questions/18752202/check-if-application-is-installed-android – Marios Koni May 05 '22 at 07:07
  • @MariosKoni , I see this link and in this link say add package into Manifest! But i don't know application package, because I get this package from server ! – Dr.KeyOk May 05 '22 at 07:10
  • You didn't mention it in your question. I think you should edit it to be more precise about your problem, so that people can help you. – Marios Koni May 05 '22 at 07:13

1 Answers1

2

Android 11 started preventing usual apps from checking ANY package name exists on device. Some of packages are still visible anyway, but not ANY

Now you can define static package names for checking these only. Use new queries tag in manifest to declare

<manifest>
    <queries>
        <package android:name="app.to.check"/>
    </queries>

If you need to check ANY custom package got from some API (unknown at moment of building app), then you may use new permission QUERY_ALL_PACKAGES. But be aware that Play Store has new policy and common apps with this perm declared won't be pulished in there. You have to provide good reason for accepting your app - this permission must be used for starting user-initiated key feature of app, e.g. device Launcher apps listing all on custom desktop.

If you are checking presence of competitors or profilig user basing on set of its apps in background - thats now forbidden

snachmsm
  • 17,866
  • 3
  • 32
  • 74
  • Thanks my fiend, but I don't know application package, because I get this package from server ! – Dr.KeyOk May 05 '22 at 08:02
  • so you can't list all apps, you need `QUERY_ALL_PACKAGES` and good reason for publish app with this perm in Play Store – snachmsm May 05 '22 at 08:26