在安卓6上获取"No permission to write APN settings"错误



我的应用程序在Android 5.0及以下可以正常工作,但是当我尝试在Android 6.0或更高的设备上运行它时,我得到了此错误:

Writing exception to parcel
                                                 java.lang.SecurityException: No permission to write APN settings
                                                     at com.android.providers.telephony.TelephonyProvider.checkPermission(TelephonyProvider.java:4058)
                                                     at com.android.providers.telephony.TelephonyProvider.query(TelephonyProvider.java:2724)
                                                     at android.content.ContentProvider.query(ContentProvider.java:1058)
                                                     at android.content.ContentProvider$Transport.query(ContentProvider.java:245)
                                                     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
                                                     at android.os.Binder.execTransact(Binder.java:453)

任何帮助将不胜感激。

也许您没有在运行时获得许可。所以这样做

    int permissionCheck = ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_APN_SETTINGS);
    if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
        //requesting permission
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_APN_SETTINGS}, 1);
    } else {
        //permission is granted and you can change APN settings
    }
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
    switch (requestCode) {
        case 1: {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                //premission granted by user
            } else {
                //permission denied by user
            }
        }
        default:
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}

相关内容

  • 没有找到相关文章

最新更新