Android 权限问题
Android permission issue
此代码对我的 phone.But 有效,但对我的朋友 phone 无效。我也有权限。我收到此错误 ;
用户 10109 和当前进程都没有 android.permission.READ_PHONE_STATE。
许可;
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
这是我的代码;
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
IMEI= telephonyManager.getDeviceId();
这可能是由于您的朋友 运行 在 Android 6.0(API 级别 23)。您需要在运行时添加权限以及 Manifest
.
中的权限
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. This approach streamlines the app install process, since the user does not need to grant permissions when they install or update the app. It also gives the user more control over the app's functionality; for example, a user could choose to give a camera app access to the camera but not to the device location. The user can revoke the permissions at any time, by going to the app's Settings screen.
参考 here for more information. Maybe take a look at 了解如何实现运行时权限,尽管在第一个 link 中也有解释。
根据新棉花糖 os,您需要为 "READ_SMS"
配置运行时权限
像这样:
String permission = Manifest.permission.READ_SMS;
if (ContextCompat.checkSelfPermission(getContext(), permission) != PackageManager.PERMISSION_GRANTED){
permissionList.add(permission);
if (!ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), permission)){
requestPermissions(new String[]{permission}), SMS_PERMISSION);
}
}
此代码对我的 phone.But 有效,但对我的朋友 phone 无效。我也有权限。我收到此错误 ;
用户 10109 和当前进程都没有 android.permission.READ_PHONE_STATE。
许可;
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
这是我的代码;
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
IMEI= telephonyManager.getDeviceId();
这可能是由于您的朋友 运行 在 Android 6.0(API 级别 23)。您需要在运行时添加权限以及 Manifest
.
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. This approach streamlines the app install process, since the user does not need to grant permissions when they install or update the app. It also gives the user more control over the app's functionality; for example, a user could choose to give a camera app access to the camera but not to the device location. The user can revoke the permissions at any time, by going to the app's Settings screen.
参考 here for more information. Maybe take a look at
根据新棉花糖 os,您需要为 "READ_SMS"
配置运行时权限像这样:
String permission = Manifest.permission.READ_SMS;
if (ContextCompat.checkSelfPermission(getContext(), permission) != PackageManager.PERMISSION_GRANTED){
permissionList.add(permission);
if (!ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), permission)){
requestPermissions(new String[]{permission}), SMS_PERMISSION);
}
}