1

I want to know from where my app is installed (who installed my app).

I need to use getInstallerPackageName(). And This method need to android.permission.INSTALL_PACKAGES permission. But this permission is not grant by the system.

this is a image Returns null in all above methods.

  1. What way do you suggest to solve the problem?

  2. What other way do you suggest for this?

Thanks.

Khoshghalb2c
  • 32
  • 1
  • 9
  • Does this answer your question? [Android INSTALL\_PACKAGES Permission and Non-PlayStore Apps](https://stackoverflow.com/questions/20553138/android-install-packages-permission-and-non-playstore-apps) – JustSightseeing Sep 11 '22 at 18:28
  • No, thanks. I know that it is not possible to use the `INSTALL_PACKAGES` permission for third-party programs. I am looking for a way to grant this permission. can i ? – Khoshghalb2c Sep 12 '22 at 06:04

2 Answers2

0

I wouldn't recommend using this permission: it probably will result in your app getting removed from google play store

You should be using REQUEST_INSTALL_PACKAGES. The INSTALL_PACKAGES permission is not allowed to be used by third party apps according to the documentation: https://developer.android.com/reference/android/Manifest.permission.html#INSTALL_PACKAGES

See also: https://android-developers.googleblog.com/2017/08/making-it-safer-to-get-apps-on-android-o.html?m=1

update (src):

Google Play restricts the use of high risk or sensitive permissions, including the REQUEST_INSTALL_PACKAGES permission, which allows an application to request installing packages. Apps targeting API level 26 or newer must hold this permission in order to use Intent.ACTION_INSTALL_PACKAGE or the PackageInstaller API.

JustSightseeing
  • 1,460
  • 3
  • 17
  • 37
  • Thanks. Can I call function `getInstallerPackageName()` with permission `REQUEST_INSTALL_PACKAGES` and get non-`null` content? – Khoshghalb2c Sep 12 '22 at 06:08
  • Still don't think so, also It is possible that google play will change it's policy and you will need to rewrite your code, if I were you I would just try to use the display name of the ContactsContract.Profile – JustSightseeing Sep 12 '22 at 09:52
0

You can use PackageManager's getInstallerPackageName() API without the need for INSTALL_PACKAGES. The android docs suggest that it is deprecated since API level 30 but:

  • android docs suggest Package Manager's getInstallSourceInfo instead, and the installSourceInfo's getOriginatingPackageName() to get the desired info. However, only getOriginatingPackageName() needs INSTALL_PACKAGES.
  • getOriginatingPackageName() is only available on Android R and above, so I guess Google may close one eye to the usage of the deprecated getInstallerPackage() for a while. And for that, you don't need the INSTALL_PACKAGES permission.
  • practical testing/usage in apps finds that getInstallerPackageName() still works as desired, and without the INSTALL_PACKAGES permission.
auspicious99
  • 3,902
  • 1
  • 44
  • 58