0
我想在Android Studio中使用TelephonyManager从设备获取手机号码,我可以在4.0版本中获得手机号码,但是当我测试版本时应用程序崩溃6.0使用TelephonyManager从Android版本6.0获得手机号码,它与最低版本一起工作
我想在Android Studio中使用TelephonyManager从设备获取手机号码,我可以在4.0版本中获得手机号码,但是当我测试版本时应用程序崩溃6.0使用TelephonyManager从Android版本6.0获得手机号码,它与最低版本一起工作
您应该检查用户是否已授予TelephonyManager 6.0版权限。您可以查看详细信息link
下面的代码检查,如果有必要的应用程序有权读取用户的联系人,并请求权限:
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.READ_CONTACTS)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_CONTACTS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
// MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// app-defined int constant. The callback method gets the
// result of the request.
}
}
@usha:没有ü检查 – DKV
如果用户给予了许可,那么我们如何访问他的联系人 – Usha
@Ushay与下面的版本相同。在访问联系人之前,您只需要获得用户的许可即可。 – DKV