How can I limit my android application installed on real device only

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I expect that my android application is allowed to install only on real device, and android-emulator can t.How can I limit my android application installed on real device only ? Thanks for any replies.

Answers

There s one way how to handle it. Just check device id (IMEI code). For emulator it s always null, so you can define either someone tries to launch it in real device or in emulator.

    TelephonyManager tm=(TelephonyManager )activity.getSystemService(Context.TELEPHONY_SERVICE);
    if(tm==null || !this.hasTelephony())
    {
        Log.v(TAG, "Can t get telephony service. Forcing shut down!");
        return false;
    }
    String deviceId=tm.getDeviceId();
    if(deviceId==null || deviceId.length() < 2)
    {
        Log.v(TAG, "Looks like emulator - bail out!");
        Toast.makeText(activity, "This special version not intended to run in this device!", 5000).show();
        return false;
    }

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/8800264/how-can-i-limit-my-android-application-installed-on-real-device-only

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils