避免权限不足时FC

pull/67/head
pppscn 4 years ago
parent a1b3f2fa31
commit cf30151c55

@ -56,9 +56,15 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
checkPermission(); checkPermission();
//获取本机号码(注意这里获取的不一定是卡槽1的) //获取本机号码(注意这里获取的不一定是卡槽1的)
String Line1Number = "";
try {
TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String Line1Number = mTelephonyMgr.getLine1Number(); Line1Number = mTelephonyMgr.getLine1Number();
Log.d(TAG, "Line1Number: " + Line1Number); Log.d(TAG, "Line1Number: " + Line1Number);
} catch (Exception e) {
Log.e(TAG, "getLine1Number fail" + e.getMessage());
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
//获取SIM卡信息 //获取SIM卡信息
getSimInfo(Line1Number); getSimInfo(Line1Number);
@ -277,6 +283,7 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
//获取SIM卡信息 //获取SIM卡信息
private void getSimInfo(String Line1Number) { private void getSimInfo(String Line1Number) {
try {
Uri uri = Uri.parse("content://telephony/siminfo"); //访问raw_contacts表 Uri uri = Uri.parse("content://telephony/siminfo"); //访问raw_contacts表
MyApplication appContext = ((MyApplication) getApplicationContext()); MyApplication appContext = ((MyApplication) getApplicationContext());
ContentResolver resolver = appContext.getContentResolver(); ContentResolver resolver = appContext.getContentResolver();
@ -301,6 +308,10 @@ public class MainActivity extends AppCompatActivity implements ReFlashListView.I
} }
cursor.close(); cursor.close();
} }
} catch (Exception e) {
Log.e(TAG, "getSimInfo fail" + e.getMessage());
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
} }
} }

Loading…
Cancel
Save