Android 安卓api23互联网许可
我正在尝试制作一个使用互联网许可的应用程序,但我在使用API 23时遇到了麻烦,我知道我需要运行许可,所以我使用谷歌来找到我需要的。 我偶然发现了以下代码:Android 安卓api23互联网许可,android,Android,我正在尝试制作一个使用互联网许可的应用程序,但我在使用API 23时遇到了麻烦,我知道我需要运行许可,所以我使用谷歌来找到我需要的。 我偶然发现了以下代码: if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { /
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权限。看看这里:你得到了什么错误?