question

bellinghammer avatar image
bellinghammer asked

Amazon Store app and PackageManager.getInstallerPackageName

What is the recommended best practice for determining at runtime if an app was installed via the Amazon Android Appstore? My preferred approach would be to use PackageManger.getInstallerPackageName link: http://developer.android.com/reference/android/content/pm/PackageManager.html#getInstallerPackageName(java.lang.String) According to the Android API documentation this is exactly what I'm looking for: Retrieve the package name of the application that installed a package. This identifies which market the package came from. Unfortunately it appears that apps installed via the Amazon Appstore (including KF) return null which is what one would expect if the user manually installed the APK. I would like to avoid generating separate APKs for each appstore in which my apps are available.
amazon appstore
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Anshul@Amazon avatar image
Anshul@Amazon answered
One way to determine if an app is installed via Amazon Appstore in production mode is by using the Amazon In-App Purchasing's onSdkAvailable(boolean isSandboxMode) method. Documentation on onSdkAvailable(boolean isSandboxMode) method from https://developer.amazon.com/sdk/in-app-purchasing/documentation/developer-guide.html Abstract from documentation: onSdkAvailable(boolean isSandboxMode) - This callback is invoked once you register your PurchasingObserver with the PurchasingManager - This method tells you if the Purchasing Framework is running in sandbox mode with test data, or in production mode with real data - If your app is downloaded via the Amazon Client, isSandboxMode will return false - The initiating method should be called within the onStart() lifecycle method On registering your PurchaseObserver, you get a async call back, onSdkAvailable(Boolean isSanboxMode). If the app is downloaded via the Amazon Client then isSandboxMode will always return false. This code will work successfully in production mode, however in development/test environment, the isSandboxMode will always return true as the app is not downlaoded via the Amazon Client in test environment. Hope this info helps.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

callmesouky avatar image
callmesouky answered
Hi Anshul, You said "one way to do it...", which is the other way? I don't want to use the In-App Purchase SDK. I just need to know the String that will be retrieved by PackageManager.getInstallerPackageName() for Amazon App Store. You are the ones who set this string, you should know it. Thanks in advance. Cheers,
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jason-gilbert avatar image
jason-gilbert answered
I would agree with @callmesouky that this is not a good answer. Why can't Amazon properly set the installer package name when the appstore installs an app? Amazon could make a small change to their appstore in probably less than an hour instead of many developers spending more than an hour implementing hacks to work around this basic error. Not a good first impression.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jason-gilbert avatar image
jason-gilbert answered
Considering a large number of apps probably want to change the app store link (as Amazon requests), this should be in the FAQ: Q: How do I determine if my app was installed from the Amazon App Store? A: PackageManager.getInstallerPackageName will return "foo".
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mttmllns avatar image
mttmllns answered
Bingo! It looks like the latest version of the App Store actually supports getInstallerPackageName()! I'm on version release-5.0000.147.0C I haven't checked the actual api yet but on a rooted device you can install an app (older already installed apps won't be updated to have installer set) and then check out /data/system/packages.xml. Sure enough: ... To match with Google's: ... Thanks Amazon! Now to check whether for apps installed with old stores if an upgrade of the app will set the installer. Discovered here: https://forums.developer.amazon.com/forums/thread.jspa?messageID=3679
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Mttmllns, Thank you for your post. Yes, in the latest version of App Store the issue has been fixed.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.