Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓api23互联网许可_Android - Fatal编程技术网

Android 安卓api23互联网许可

Android 安卓api23互联网许可,android,Android,我正在尝试制作一个使用互联网许可的应用程序,但我在使用API 23时遇到了麻烦,我知道我需要运行许可,所以我使用谷歌来找到我需要的。 我偶然发现了以下代码: if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { /

我正在尝试制作一个使用互联网许可的应用程序,但我在使用API 23时遇到了麻烦,我知道我需要运行许可,所以我使用谷歌来找到我需要的。 我偶然发现了以下代码:

if (ContextCompat.checkSelfPermission(this,
                         Manifest.permission.READ_CONTACTS)
                         != PackageManager.PERMISSION_GRANTED) {

// Already declined the permission
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                                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 for the first time
    ActivityCompat.requestPermissions(this,
                   new String[]{Manifest.permission.READ_CONTACTS},
                   REQUEST_CONTACTS);

    // REQUEST_CONTACTS is an
    // app-defined int constant. The callback method gets the
    // result of the request.
}
} 从本网站:

问题是,我需要互联网,但我在网上找到的所有示例都是针对联系人的,应该是类似的,但当我替换REQUEST_联系人时 如果我收到一个错误,我应该用什么替换它



谢谢您的回答,我只需要在清单上添加权限。

对于Internet,您不需要向用户请求权限。但是,您确实需要在应用程序清单文件中使用
uses permission
元素声明它。

您不需要在INTERNET上这样做。您应该仅在“危险”权限下执行此操作,例如阅读联系人或位置。在您的情况下,您应该在清单上添加internet权限。看看这里:你得到了什么错误?