Detect If App Was Downloaded from Android Market

Detect if an app is installed from Play store

This method will check if your app has been installed from the Play Store.

boolean verifyInstallerId(Context context) {
// A list with valid installers package name
List<String> validInstallers = new ArrayList<>(Arrays.asList("com.android.vending", "com.google.android.feedback"));

// The package name of the app that has installed your app
final String installer = context.getPackageManager().getInstallerPackageName(context.getPackageName());

// true if your app has been downloaded from Play Store
return installer != null && validInstallers.contains(installer);
}

Some days ago I released an Android library, PiracyChecker, that protects your app using some techniques, such as Google Play Licensing (LVL), APK signature protection and installer ID (this one).

Detect if app was downloaded from Android Market

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

Is there a way to detect if app was installed with Market or not?

In your activity do


PackageManager pm = getPackageManager();
String installationSource = pm.getInstallerPackageName(getPackageName());

installationSource will now hold the package name of the app that installed your app.

testing with an app of mine installation source is "com.google.android.feedback" when installed via google market, null if installed via debugger.

android: Detect if App was downloaded from market

It seems that this can't be done.

How to detect if a specific app is being downloaded/installed by the Google Play store?

Is there any way to detect if the user is in the process of installing
app X?

The closest you'll get to this is by using a NotificationListenerService.

From the docs:

A service that receives calls from the system when new notifications
are posted or removed.

But considering this Service was recently added in API level 18 and your use case, you might consider using a BroadcastReceiver and listening for when android.intent.action.PACKAGE_ADDED and android.intent.action.PACKAGE_REMOVED are called. This way once an app is installed or removed, you can do what you want with the package name, like provide a link to the Play Store.

Here's an example:

BroadcastReceiver

public class PackageChangeReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
if (intent == null || intent.getData() == null) {
return;
}

final String packageName = intent.getData().getSchemeSpecificPart();
// Do something with the package name
}

}

In your AndroidManifest

<receiver android:name="your_path_to.PackageChangeReceiver" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />

<data android:scheme="package" />
</intent-filter>
</receiver>

How to determine which android market was used to download my app

Generally if you use some advertising to distribute your app you can use some tools of Google:

In short, you need to insert Googgle Analitics to your app (if you not already use it of course), and use it tool that called:

Campaign Measurement

Then you could sign Receiver of the installment :

<receiver
android:name=".system.RefferReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>

And you could handle the logic inside the receiver:

public class RefferReceiver extends BroadcastReceiver {

@Override
public void onReceive(final Context context, Intent intent) {
String referrer = intent.getStringExtra("referrer");
//do some logic
}

Edited:
Sorry, I didn't read your question properly. if you just want to know the market source of your app You can use :

 String installerMarket = getPackageManager().getInstallerPackageName("your_package_name");
if (installerMarket == null){
//do some default case
}
else if ("com.android.vending".equals(installerMarket)) {
//link to google play
} else if ("com.amazon.venezia".equals(installerMarket)){
//link to amazon
} else if //you got the idea, you need to know the name of every market store installer
}

Detect if an Android app was downloaded from Google Play vs Amazon vs Other

As of just recently, the Amazon Appstore returns sane values for PackageManager.getInstallerPackageName()

PackageManager pm = context.getPackageManager();
String installerPackageName = pm.getInstallerPackageName(context.getPackageName());

if ("com.android.vending".equals(installerPackageName)) {
//do google things
} else if ("com.amazon.venezia".equals(installerPackageName)) {
//do amazon things
}

See here:
https://forums.developer.amazon.com/forums/thread.jspa?threadID=680

Examples for rate this app links:

Google Play-

market://details?id=PACKAGANAME

Amazon Store

http://www.amazon.com/gp/mas/dl/android?p=PACKAGENAME

or

amzn://apps/android?p=com.amazon.mp3



Related Topics



Leave a reply



Submit