I want to stop showing ads if the apk is sideloaded version i.e. if it is not installed from play store. So I did this by:
String installer = getPackageManager().getInstallerPackageName(
"com.example.myapp");
if (installer == null) {
// app was illegally downloaded from unknown source.
// dear user, please re-install it from market
}
else if(installer.equals("com.android.vending") {
// app was installed legally
}
Now in one stack overflow answer (link): https://stackoverflow.com/a/36299631/12182265
I found that:
The installer packagename can change in the future. For example, the installer package name use to be "com.google.android.feedback"
(see here) and now it is "com.android.vending"
.
So I did some search and I found:
GooglePlayServicesUtilLight.GOOGLE_PLAY_STORE_PACKAGE
constant.
So instead of checking hardcoding value i.e. "com.android.vending"
can I use GooglePlayServicesUtilLight.GOOGLE_PLAY_STORE_PACKAGE
? Will below code work?
String installer = getPackageManager().getInstallerPackageName(
"com.example.myapp");
if (installer == null) {
// app was illegally downloaded from unknown source.
// dear user, please re-install it from market
}
else if(installer.equals(GooglePlayServicesUtilLight.GOOGLE_PLAY_STORE_PACKAGE)) {
// app was installed legally
}
Why I don't want to show ads in sideloaded apk?
Answer: Currently I have app on play store which I made not available in 10 countries. So I have doubt that there ares some users from those 10 countries who installed sideloaded version of it from third party sites which I cannot control. And they clicked on banner ads in my app which resulted ad serving limit placed on my admob account. Am I correct? Or sideloading will not be the cause of ad serving limit?