How to determine which Android market was used to download my application

I plan to distribute my application not only on Google Play, but also in several other markets, such as Opera Mobile Store, Yandex Store, Amazon App Store. For the "Rate" button, I need to set a link to the store page. Can I find out which market was used to download my application?

Of course, I can compile an invididual APK for each market, but I want to make one universal APK. Various IAP APIs are handled by the OpenIAB library, but now I run into a problem with a link to the market.

+4
source share
1 answer

, - , Google:

, Googgle Analitics ( , ), , :

:

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

:

public class RefferReceiver extends BroadcastReceiver {

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

: , . , :

 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
    }
+5

All Articles