0

I have used Intent-filter PACKAGE_NAME to capture the package name of the newly installed app from Playstore or by adb command.Can anyone suggest me how to differentiate between package installation from playstore and from adb.

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);

This will work both for adb installation and installation from playstore. I need it to be specific to playstore.

Champ
  • 3
  • 2
  • Have you seen: [How to know if an app has been downloaded from Google Play or Amazon?](https://stackoverflow.com/q/11072079/295004) and [Is it ok to check legality of installing paid android app by checking getInstallerPackageName?](https://stackoverflow.com/a/36299631/295004) – Morrison Chang Jul 17 '20 at 04:09

1 Answers1

0

You can use packageManager.getInstallerPackageName

And com.android.vending is the package of Play Store

tadev
  • 204
  • 1
  • 5
  • MainActivity.java IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED); – Champ Jul 19 '20 at 18:18
  • MyReceiver.java String packageName = Objects.requireNonNull(intent.getData()).getEncodedSchemeSpecificPart() createNotification(packageName) onAppLaunch(packageName) – Champ Jul 19 '20 at 18:18
  • I added try { final ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0); if("com.android.vending".equals(packageManager.getInstallerPackageName(applicationInfo.packageName))) { // App was installed by Play Store Log.d(TAG, "Playstore installation:" +packageManager.getInstallerPackageName(applicationInfo.packageName));} Added code in onReceive() in MyReceive java file , not working. @tadev – Champ Jul 19 '20 at 18:24