如何在android rooted oreo中授予WRITE_APN_SETTINGS权限

时间:2018-05-08 11:37:57

标签: android apn

我可以轻松地在android 4.2.2中以编程方式设置,添加,更新,删除APN,但在android 6之上,我无法使用root设备中的运行时权限授予WRITE_APN_SETTINGS权限作为系统应用程序。 谢谢你的解决方法。

1 个答案:

答案 0 :(得分:0)

如果运行6.1以上的app看起来

,请使用运行时权限检查
 int permissionCheck = ContextCompat.checkSelfPermission(YourActivity, Manifest.permission.WRITE_APN_SETTINGS);
        if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
            //requesting permission
            ActivityCompat.requestPermissions(YourActivity, new String[]{Manifest.permission.WRITE_APN_SETTINGS}, 1);
        } else
            //permission is granted      

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        switch (requestCode) {
            case 1: {
                if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    //permission granted by user
                } else
                    //permission denied by user               
            }         

        }
    }

希望它能帮到你!!