Question

I'm porting an iOS app to Android, and I need to change the API URL depending on if it's plugged in via USB, downloaded as an .apk or installed via the Google play store.

This is so I can use my local dev API, a staging API and then obviously the public production/release API.

I've used to check if the app is running through Eclipse:

if ( ( appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE ) != 0 ) {
    debug_value = "1";
}

But I need to check the difference between test/release.

In iOS I've just tested for the DEBUG preprocessor macro, and added one for ADHOC as well.

Was it helpful?

Solution 2

I've found out I can use the getInstallerPackageaName() method to check if it's been installed via an application (like Google Play) or it'll return NULL.

I've used this code (it's a Cordova app):

PackageManager packageManager = this.cordova.getActivity().getPackageManager();
String installer = packageManager.getInstallerPackageName( "com.myapp" );

if ( installer == null ) {
    // not installed via application (like Google Play)
} else {
    // installed via application
}

I should probably expand this to specifically check for store names, but I'm just starting out with this and there seems to be some discrepancy about what installer package name Google Play will return (see questions listed below)

Android Docs for getInstallerPackageName():

http://developer.android.com/reference/android/content/pm/PackageManager.html#getInstallerPackageName(java.lang.String)

Similar questions on SO:

OTHER TIPS

I don't believe you can see the difference between *.apk and Google Play if they're the actual same build.

On the other hand if you're using Gradle it's quite straight forward to add keywords to the name that you can check later.

That's an example from my app:

    buildTypes {
        debug {
            versionNameSuffix = "-DEBUG"
        }
        release {
            signingConfig signingConfigs.release
        }
    }

this allows us to check on the app for:

getPackageManager()
     .getPackageInfo(getPackageName(), 0)
     .versionName
     .contains("DEBUG");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top