Android- Wi -Fi建议API的更改批准状态(许可)
我的应用程序使用 wi-fi建议api 。我第一次想添加建议时,操作系统要求用户允许该应用程序要添加网络配置。
如果用户拒绝权限,则启用它的唯一方法是推动用户手动打开“特殊访问”设置并再次允许它。请参阅
EDIT 1:
I want to open the "special access" settings dialog programmatically as described in
结束编辑1
有什么办法可以
- a)以编程方式打开此设置菜单?
- b)请求
access_wifi_state
和change_wifi_state
的权限?
对于选项a)我试图找到相应的活动并这样称呼:
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.data = Uri.parse("package:${reactApplicationContext.packageName}")
reactApplicationContext.currentActivity!!.startActivity(intent)
但是我找不到所需意图的正确值。
对于选项b)我试图照常索取许可:
class WifiPermissionActivity: AppCompatActivity() {
private val requestPermissionRequestCode = 100
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val permissions = arrayOf(
Manifest.permission.CHANGE_WIFI_STATE,
Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.ACCESS_NETWORK_STATE)
requestPermissions(permissions, requestPermissionRequestCode)
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
if (requestCode != requestPermissionRequestCode) {
return
}
val permissionGranted = grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED
val resultIntent = Intent()
resultIntent.putExtra("PERMISSION_GRANTED", permissionGranted)
setResult(RESULT_OK, resultIntent)
finish()
}
}
但这不起作用。结果,我总是得到packagemanager.permission_granted
。
我在androidManifest.xml
中定义了以下权限。
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
编辑2
这是一份录音,显示了如何手动打开此菜单。我需要一种编程方式打开此菜单的方法。
My app uses the Wi-Fi Suggestion API. The first time I want to add a suggestion, the operating system asks the user to allow that the app wants to add a network configuration.
If the user rejects the permission, the only way to enable it again is to push the user to manually open the "special access" settings and allow it again. See last paragraph "Changing approval status for app".
EDIT 1:
I want to open the "special access" settings dialog programmatically as described in Android programmatically open the settings page for all the apps that controls draw over permission. But in my case I need to open Wi-Fi control
and not Appear on top
, but I couldn't find the required Activity/Intent.
End EDIT 1
Is there any way to
- a) open this settings menu programmatically?
- b) request the permission for
ACCESS_WIFI_STATE
andCHANGE_WIFI_STATE
?
For option a) I have tried to find the respective activity and call it like this:
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.data = Uri.parse("package:${reactApplicationContext.packageName}")
reactApplicationContext.currentActivity!!.startActivity(intent)
But I can't find the correct value for the required Intent.
For option b) I have tried to request the permission as usual:
class WifiPermissionActivity: AppCompatActivity() {
private val requestPermissionRequestCode = 100
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val permissions = arrayOf(
Manifest.permission.CHANGE_WIFI_STATE,
Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.ACCESS_NETWORK_STATE)
requestPermissions(permissions, requestPermissionRequestCode)
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
if (requestCode != requestPermissionRequestCode) {
return
}
val permissionGranted = grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED
val resultIntent = Intent()
resultIntent.putExtra("PERMISSION_GRANTED", permissionGranted)
setResult(RESULT_OK, resultIntent)
finish()
}
}
But this does not work. I always get PackageManager.PERMISSION_GRANTED
as a result.
I have defined the following permissions in my AndroidManifest.xml
.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
EDIT 2
Here is a recording that shows how to open this menu manually. I need a way to open this menu programmatically.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论