这是我的代码但不能正常工作
tManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
EditText e3 = (EditText) findViewById(R.id.phno);
e3.setText(tManager.getLine1Number());
答案 0 :(得分:1)
这对我来说很好
在onCreate内部
Button btnSubmit = (Button) findViewById(R.id.buttonLogin);
btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TelephonyManager telephonyManager = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
String CountryISO = telephonyManager.getSimCountryIso().toString().toUpperCase();
String getSimSerialNumber = telephonyManager.getSimSerialNumber();
String getSimNumber = telephonyManager.getLine1Number();
Log.e("Telephone Data : "getSimSerialNumber + " " + getSimNumber);
}
});
不要忘记在清单中添加权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>