Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if app was downloaded from Android Market

Tags:

android

I have an Android library that uploads data to a test server and production server. I'd like developers using this library to use the test server when developing, and production server when the app is downloaded from Android Market.

Is this possible for an app to tell where it came from (Market or non-Market?) I would imagine one could detect the presence of the signed JAR file.

like image 898
sehugg Avatar asked Jun 12 '09 13:06

sehugg


People also ask

How can I tell when an app was downloaded Android?

You can view the app download history in Google Play Store from the Installed or Library sections of the Store. The Installed section shows you all the apps currently installed on your Android device.

How do I know if an app is downloaded from Play Store?

On your Android phone, open the Google Play store app and tap the menu button (three lines). In the menu, tap My apps & games to see a list of apps currently installed on your device. Tap All to see a list of all apps you've downloaded on any device using your Google account.


3 Answers

Yes, you could use the signature for that. If you use a debug key to sign your app during development and a release key when uploading your app to the market you can check for the signature that the app was signed with and based on that use test or production server. Here is a small code piece to read the signature of your app:

    try {
        PackageManager manager = context.getPackageManager(); 
        PackageInfo appInfo = manager.getPackageInfo(
            YOUR_PACKAGE_NAME, PackageManager.GET_SIGNATURES);

        // Now test if the first signature equals your debug key.
        boolean shouldUseTestServer = 
            appInfo.signatures[0].toCharsString().equals(YOUR_DEBUG_KEY);

    } catch (NameNotFoundException e) {
        // Expected exception that occurs if the package is not present.
    }

YOUR_PACKAGE_NAME must be something like 'com.wsl.CardioTrainer'. It must be the package name you used in your AndroidManifest.xml. Good Luck

mark

like image 182
maximon Avatar answered Oct 16 '22 19:10

maximon


Starting with API 5, you can use PackageManager.getInstallerPackageName(String). From the documentation:

Retrieve the package name of the application that installed a package. This identifies which market the package came from.

To get the package of the Android Market, this post may help.

like image 10
Phil Avatar answered Oct 16 '22 18:10

Phil


From what I can tell there is nothing that the Market Application does to "flag" an application to say that it was downloaded from the market.

I have seen this issue approached in a different manner by another Android library. The AdMob Android SDK is free to download and use as described on their wiki. This library serves ads, so they have the same desire to be able to determine if the application that is currently running is being tested by the developer or if it is being used "in the wild". Their approach was to require that the developer set a "testing" attribute in the XML or to call their libraries "setTesting(boolean)" function to let the library know which ads to serve. This is obviously more of a manual approach that relies on the developer to change one line of code or XML before publishing.

like image 3
snctln Avatar answered Oct 16 '22 19:10

snctln