限制特定IMEI号码的应用程序

时间:2016-10-14 12:39:26

标签: android imei

我开发了公司电话簿的应用程序。为了限制其分发给非公司人员,我必须将应用程序限制为特定的IMEI号码。       所以无论谁想要我的应用程序,他都会注册电子邮件ID和IMEI号码并使用该IMEI号码我应该将.apk发给他。

<StackPanel Orientation="Horizontal">
    <TextBlock Text="oh this is a label" TextWrapping="Wrap" />
    <TextBlock Text="and this should be a very, very, very, very, very, very, very, very, very, very long text" TextWrapping="Wrap" />
</StackPanel>

(我正在使用Adobe Flash构建器,我正在尝试使用Flex平台)。

2 个答案:

答案 0 :(得分:0)

根据您在评论中的解释。我会告诉你,我认为这不是一个好的&#34;鉴定&#34;解。我鼓励您使用单个应用程序,并在服务器端使用数据库检查IMEI。

此外,我必须说高级用户可以伪造设备的IMEI。

但无论如何,如果你想制作解决方案,代码就很简单了。您只需要使用静态变量存储IMEI并在主活动中进行检查。 如果IMEI正确,请运行应用程序,否则显示消息并关闭。这就是你有一个单一的IMEI应用程序&#34;

的方式
public class MainActivity extends AppCompatActivity {

    private final static String AUTHORIZED_IMEI = "XXXXXXXXXXXXXX";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // get device IMEI
        TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
        String deviceImei = telephonyManager.getDeviceId();

        if (AUTHORIZED_IMEI.equals(deviceImei)) {
            // AUTHORIZED
            // Code to run within onCreate
        } else {
            Toast.makeText(this, "DEVICE NOT AUTHORIZED", Toast.LENGTH_LONG).show();
            finish();
        }
    }
}

您还需要在清单文件中写入权限

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
  

注意:在Android 6中,您需要在运行时处理此问题。

答案 1 :(得分:0)

private final static String authorisedImei = "xxxxxxxx";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        // ActivityCompat#requestPermissions;
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_PHONE_STATE}, 1);

        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
        } else {

            return;
        }
    }
        String deviceImei = telephonyManager.getDeviceId();

        if (authorisedImei.equals(deviceImei)) {
            textView = findViewById(R.id.text2);
            textView.setText(deviceImei + " - Authorised");
        }

        else {
          textView = findViewById(R.id.text2);
          textView.setText(deviceImei + " - Not authorised");

            new CountDownTimer(5000, 1000) {

                public void onTick(long millisUntilFinished) {
                    textView = findViewById(R.id.text1);
                    textView.setText("seconds remaining: " + millisUntilFinished / 1000);
                }

                public void onFinish() {
                    finish();
                }
            }.start();
        }
    }
}