Roman Shuvalov
Roman Shuvalov

Reputation: 385

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

I plan to distribute my app not only on Google Play, but on several other markets, such as Opera Mobile Store, Yandex Store, Amazon App Store. For "Rate" button I need to link to store page. Is it possible to find out which market was used to download my app?

Of course I can compile invididual APKs for every market but I want to make one universal APK. Different IAP APIs are solved by OpenIAB library, but now I stuck to problem with linking to market.

Upvotes: 4

Views: 457

Answers (1)

yshahak
yshahak

Reputation: 5096

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
    }

Upvotes: 5

Related Questions