简体   繁体   中英

Is there any way I can identify when my Android app is built by F-Droid?

I have a GPL android app, which has recently been included in F-Droid.

In the Google Play's I'm using AdMob to receive some income, but when the app is built by F-Droid servers, they use this AdMob clone so the code builds without the need of adding a binary proprietary library. Because of that, ads are not shown.

However, I would like to add a small "banner" that allow users to visit my site when the ad is not shown: I won't have the direct income the adds give me, but at least I'll allow users to go to my page and, if they want, give a donation.

My question is: is ther any way to know "IM_USING_THE_REAL_ADMOB" in the following code?

Another option would be to know who signed the APP.

Any help?

LinearLayout layout = (LinearLayout) findViewById(R.id.adLayout);

if(IM_USING_THE_REAL_ADMOB) { 
    // Google Play version of the app

    adView = new AdView(this, AdSize.BANNER, "ad-code");

    layout.addView(adView);

    AdRequest request = new AdRequest();

    adView.loadAd(request);
} else {

    // F-Droid versions of the App
    ImageView myImage;        

    layout.AddView(image)
}

I tried to look at the signature, as "CommonsWare suggested, by doing this

PackageManager pm = getPackageManager();
try {
    PackageInfo a = pm.getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
    byte[] raw = a.signatures[0].toByteArray();

    String sig = MessageDigest.getInstance("MD5").digest(raw).toString();

    _sourceTextEditor.setText(sig);
    }
    catch (Exception e) {

        return false;
    }

but i got different result in two phones installing the same signed app. Am I doing something wrong?

看起来替换的AdMob的AdView始终会向isReady和isRefreshing返回false-可以将此行为与官方AdMob的预期AdView行为进行比较,并相应地调整您的应用。

I would agree with powerj1984 that the right answer is for the faux AdMob library to let you know that it is the faux AdMob library.

If, for whatever reason, that is not possible, you can find out the details of the public key of the keystore that signed your app. Use PackageManager and getPackageInfo() to retrieve the PackageInfo for your own package, specifying GET_SIGNATURES as the flag. The signatures field on PackageInfo contains an array of signatures, where there should only be one. That, in turn, is really the byte[] representation of a X509Certificate . This sample project shows how to display signature information for any installed app.

If your app is GPL, people have both the source, and have the right to modify the source. There is no way to force them to provide you with an income.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM