Monday, January 10, 2011

Check if the user is running AdBlock

A lot of applications on the android market use admob, or some other advertising method to keep the application free but still be able to generate some revenue. The ads are good for both the developer and the user. It generates revenue for the developer, and gives the user relevant advertising.

There is an application, which was recently pulled off the android market, called AdBlock that blocks these advertisers from displaying ads. This application can be a thorn in the side of the developers, as it is hindering income that the developer could be receiving.

Now you could probably argue that these people that run AdBlock wouldn’t click on the ads any how, and for the most part, that is probably true. But at the same time, a lot of applications on the market offer a license key or some other way to remove the ads from the application buy paying the developer a small fee. If the user is running AdBlock, they are circumventing this licensing model and in a way, stealing the application.

One of the great things about android is the ability to launch other intents. And by having this ability, we can check if the user has AdBlock installed. If they have it installed, we can then render the application useless until they remove AdBlock, or purchase the license.

This code block below will check if the user is running AdBlock, if they are, it will display an alert dialog and launch the market to purchase a license, or they can close the application.

private static void performCheck ( final Activity activity ) {
PackageManager pm
= activity.getPackageManager ();
Intent intent
= pm.getLaunchIntentForPackage ( "de.ub0r.android.adBlock" );
if ( Reflection.isPackageInstalled ( activity, intent ) ) {
new AlertDialog.Builder ( activity )
.setTitle (
"License Required" )
.setMessage (
"Since you are running software to "
+ "block the ads that keep this software free, you must purchase a "
+ "license to use this software from "
+ "the android market." )
.setPositiveButton ( android.R.
string.ok, new DialogInterface.OnClickListener () {
@Override
public void onClick ( DialogInterface dialog, int which ) {
Reflection.launchMarketDetails ( activity, Reflection.getPackageName ( activity )
+ ".license" );
activity.finish ();
}
} ).setNegativeButton ( android.R.
string.cancel, new DialogInterface.OnClickListener () {
@Override
public void onClick ( DialogInterface dialog, int which ) {
Toast
.makeText (
activity,
"You will not be able to use this application until a license is purchased or the ad "
+ "blocking is removed.",
Toast.LENGTH_LONG ).show ();
activity.finish ();
}
} ).show ();
}
}

Check if the user is running AdBlock

A lot of applications on the android market use admob, or some other advertising method to keep the application free but still be able to generate some revenue. The ads are good for both the developer and the user. It generates revenue for the developer, and gives the user relevant advertising.

There is an application, which was recently pulled off the android market, called AdBlock that blocks these advertisers from displaying ads. This application can be a thorn in the side of the developers, as it is hindering income that the developer could be receiving.

Now you could probably argue that these people that run AdBlock wouldn’t click on the ads any how, and for the most part, that is probably true. But at the same time, a lot of applications on the market offer a license key or some other way to remove the ads from the application buy paying the developer a small fee. If the user is running AdBlock, they are circumventing this licensing model and in a way, stealing the application.

One of the great things about android is the ability to launch other intents. And by having this ability, we can check if the user has AdBlock installed. If they have it installed, we can then render the application useless until they remove AdBlock, or purchase the license.

This code block below will check if the user is running AdBlock, if they are, it will display an alert dialog and launch the market to purchase a license, or they can close the application.

private static void performCheck ( final Activity activity ) {
PackageManager pm
= activity.getPackageManager ();
Intent intent
= pm.getLaunchIntentForPackage ( "de.ub0r.android.adBlock" );
if ( Reflection.isPackageInstalled ( activity, intent ) ) {
new AlertDialog.Builder ( activity )
.setTitle (
"License Required" )
.setMessage (
"Since you are running software to "
+ "block the ads that keep this software free, you must purchase a "
+ "license to use this software from "
+ "the android market." )
.setPositiveButton ( android.R.
string.ok, new DialogInterface.OnClickListener () {
@Override
public void onClick ( DialogInterface dialog, int which ) {
Reflection.launchMarketDetails ( activity, Reflection.getPackageName ( activity )
+ ".license" );
activity.finish ();
}
} ).setNegativeButton ( android.R.
string.cancel, new DialogInterface.OnClickListener () {
@Override
public void onClick ( DialogInterface dialog, int which ) {
Toast
.makeText (
activity,
"You will not be able to use this application until a license is purchased or the ad "
+ "blocking is removed.",
Toast.LENGTH_LONG ).show ();
activity.finish ();
}
} ).show ();
}
}