目标是获取IMEI码,已经加入READ_PHONE_STATE的权限
以下代码在MainActivity中,手机真机运行时,按下按钮直接闪退了
```package com.example.imei_get;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private static Context context; //全局的上下文
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = getApplicationContext();
}
public void get_imei(View v){
TextView txv= (TextView) findViewById(R.id.textview);//
TelephonyManager TelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String szImei = TelephonyMgr.getDeviceId();
txv.setText(szImei);
}
}