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.