直接上干货,不多说
TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String[] phone = manager.getLine1Number().split("");
StringBuilder sb =new StringBuilder();
if (phone.length >0) {
for (int i =0; i < phone.length; i++) {
if (i <=6) {
sb.append(phone[i]);
}else if (i <=11) {
sb.append("*");
}else {
sb.append(phone[i]);
}
}
Log.d("Tag",sb.toString());
}
注意:获取手机号需要权限申请READ_SMS、READ_PHONE_NUMBERS、READ_PHONE_STATE。