whitespace COMPANY whitespace SERVICES whitespace PRODUCTS whitespace PURCHASE whitespace SUPPORT whitespace CONTACTS whitespace Home whitespace Contact Us whitespace Site Map whitespace
whitespace
WHY ARTFULBITS
whitespace
OUR APPROACH
whitespace
OUR TEAM
whitespace
FACT SHEET
whitespace
NEWS & EVENTS
whitespace
PRIVACY
whitespace
whitespace

Integrate Anti-Piracy check into your Application.


Overview

Provided below source code shows how to check is running device in Android anti-piracy black list database or not.

Set permissions in AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest
  xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.artfulbits.aiCurrency"
  android:versionCode="3"
  android:versionName="1.2.0">
  <application
    android:icon="@drawable/app_icon"
    android:theme="@android:style/Theme.NoTitleBar"
    android:label="@string/app_name"
    android:name=".CurrencyApplication"
    android:allowClearUserData="true">
   
   <uses-permission android:name="android.permission.INTERNET" />
</manifest>

Source Code integration example

package aiCharts.GallerySample;

import com.artfulbits.aiCharts.ChartView;
import com.artfulbits.aiCharts.Base.*;
import com.artfulbits.aiCharts.Types.ChartTypes;

import android.app.*;
import android.app.AlertDialog.Builder;
import android.os.Bundle;
import android.view.*;

public class TestActivity extends Activity
{
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // shutdown process if device in black list
    if( getIMEIStatus() > 0 )
      Process.killProcess(Process.myPid());
  }

  /**
  * Determines status of device's IMEI.
  * 
  * @return -1 - imei status retrieval failed. 0 - Green status 1 to 3 - Yellow
  * status 3 to 5 - Brown status above 5 - Red status
  */
  public int getIMEIStatus()
  {
    // 1. Get device ID
    TelephonyManager manager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    String sDeviceID = manager.getDeviceId();
    // 2. Fetch for IMEI data.
    // Will look like
    // http://www.artfulbits.com/android/antipiracycheck.ashx?IMEI=123456789123456
    String url = "http://www.artfulbits.com/android/antipiracycheck.ashx?imei="
                + sDeviceID;
    // Server will return 200 if request post was successful.
    int http_ok = 200;
    // Create new http client.
    HttpClient client = new DefaultHttpClient();
    // Create new http post.
    HttpPost post = new HttpPost(url);
    // Cache http response.
    HttpResponse response = null;
    // Will return -1 unless server provides its own value.
    int imeiStatus = -1;
    try
    {
      // Executind post.
      response = client.execute(post);
      // Making sure we've received correct status code.
      if(response.getStatusLine().getStatusCode() == http_ok)
      {
        // Retrieving content stream.
        InputStream stream = response.getEntity().getContent();
        // Decorating stream with Input stream reader
        InputStreamReader isr = new InputStreamReader(stream);
        // Decorating input stream reader with buffered stream reader.
        BufferedReader reader = new BufferedReader(isr);
        // Reading imei status from stream.
        imeiStatus = Integer.parseInt(reader.readLine());
        // Closing buffered reader will recursively close decorated input stream
        // reader and input stream.
        reader.close();
      }
    }
    catch(Exception e)
    {
          e.printStackTrace();
    }
    return imeiStatus;
  }
}
Company | Services | Practices | Technologies | Career | Contacts | Privacy
© 2005-2016 ArtfulBits. All rights reserved.