0

I have an appstore that I want to do the same as google play store and amazon store which have unique values when calling getInstallerPackageName(). like apps that were installed from amazon would return com.amazon.venezia and apps installed from google play would return com.android.vending.

is it possible I can do the same? so when calling getInstallerPackageName() for the apps that were downloaded and installed from my appstore would return for example com.myapp.vending?

also, i know calling getInstallerPackageName() would return null if the app is sideloaded, but there might be cases where A app can be downloaded and installed from another 3rd party source and not from my app. both ways of installing this A app would return null when calling getInstallerPackageName().

user1865027
  • 3,505
  • 6
  • 33
  • 71
  • Possible duplicate of [set "installer" package value to be returned in getInstallerPackageName()](http://stackoverflow.com/questions/9146820/set-installer-package-value-to-be-returned-in-getinstallerpackagename) – Code-Apprentice Aug 12 '16 at 23:03

1 Answers1

2

To set the installer package name, you first need to install the app using an Intent, as it appears you have figured out. After the installation is successful, you can call setInstallerPackageName() with appropriate parameters.

Sources:

Install Application programmatically on Android

PackageManager.setInstallerPackageName()

Community
  • 1
  • 1
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • I'm doing the install prompt by throwing an intent like the link you provided. will that throw the package name i have in my manifest when calling `getInstallerPackageName()`? – user1865027 Aug 12 '16 at 21:34
  • @user1865027 I'm not entirely certain. I suggest testing it yourself. You could make a dummy app to install with your installer app. – Code-Apprentice Aug 12 '16 at 22:05
  • no it doesnt work. i cant find a way to set InstallerPackageName. packageManager has the method but makes no sense to set it after the installation. – user1865027 Aug 12 '16 at 22:55
  • Did you [read the documentation](https://developer.android.com/reference/android/content/pm/PackageManager.html#setInstallerPackageName(java.lang.String,%20java.lang.String))? You can call `setInstallerPackageName()` in the installer app. – Code-Apprentice Aug 12 '16 at 23:02
  • yea, but the thing is i dont know how/where to call `setInstallerPackageName(). im basically throwing an intent with path to the apk like the link you provided. i can only set it after installation completes – user1865027 Aug 12 '16 at 23:21
  • i cant set InstallerPackageName in an intent – user1865027 Aug 12 '16 at 23:28
  • In your installer app: 1. Install an app. 2. Call `setInstallerPackageName()` with the desired parameters. – Code-Apprentice Aug 12 '16 at 23:40
  • yes, that post tells you to pass the intent to the system and let android installer to handle the installation. my app only downloads apk then fire up intent – user1865027 Aug 12 '16 at 23:46
  • @user1865027 I think that using an Intent to allow the Android system to install the app is exactly the way to go. – Code-Apprentice Aug 13 '16 at 19:04
  • then there's no way to set installerPackageName. its gonna just be an intent and no `PackageManager` – user1865027 Aug 15 '16 at 18:36
  • @user1865027 Hopefully my edited answer is more clear. I have just tried to add a little more detail to my previous comment. You certainly can set the installer package name by getting the `PackageManager` and calling `setInstallerPackageName()`. – Code-Apprentice Aug 15 '16 at 19:31
  • thanks for the edited answer. but like you said, i can only set installerPackageName **after** the app is installed. there's no additional information passed in the `BroadcastReceiver` to distinguish whether the app was installed from the intent passed by my app or any other apps. – user1865027 Aug 15 '16 at 20:12
  • my point here is that i have something else i want to do after installation, but it wouldnt make sense to call my method if the new app is installed by any other app – user1865027 Aug 15 '16 at 20:14