HttpUrlConnection request error (Missing Internet permission when the permission is enabled)

此生再无相见时 提交于 2019-12-07 15:49:27

This will help you. Write the following in your onCreate method

int PERMISSION_ALL = 1;
    String[] PERMISSIONS = {Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_SMS, Manifest.permission.CAMERA};

    if (!hasPermissions(this, PERMISSIONS)) {
        ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL);
    }

And get this method

 public static boolean hasPermissions(Context context, String... permissions)
{
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null)
    {
        for (String permission : permissions)
        {
            if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED)
            {
                return false;
            }
        }
    }
    return true;
}

The application will ask for only those permission which the application needs, that too only once. If it works upvote and do let me know. It worked for me

joshgoldeneagle

HttpUrlConnection request also requires android.permission.ACCESS_NETWORK_STATE. Do you also have this permission listed in the manifest?

Please post your manifest file so we can see that android.permission.ACCESS_NETWORK_STATE, and android.permission.INTERNET are both listed without any spelling, capitalization, syntax errors.

The issue can also happen if a user has rooted their Android device and tinkered with the permissions. How do you know the user has not rooted the device? Can you reproduce the problem on any of your own devices?

See more detail on this issue here: SecurityException: Permission denied (missing INTERNET permission?)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!