3

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 and CHANGE_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.

Open wifi control settings manually

Raman
  • 548
  • 1
  • 7
  • 17
  • "request the permission for ACCESS_WIFI_STATE and CHANGE_WIFI_STATE?" -- those are not `dangerous` permissions and do not need to be requested at runtime. Just have them in the manifest. – CommonsWare Jun 07 '22 at 12:47
  • @CommonsWare even though this doesn't work. Since the user has reject this once, I always receive `WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_APP_DISALLOWED`. See https://developer.android.com/reference/android/net/wifi/WifiManager#STATUS_NETWORK_SUGGESTIONS_ERROR_APP_DISALLOWED – Raman Jun 07 '22 at 13:28
  • "Since the user has reject this once, I always receive WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_APP_DISALLOWED" -- that does not change the fact that `ACCESS_WIFI_STATE` and `CHANGE_WIFI_STATE` are not `dangerous` permissions and do not need to be requested at runtime. – CommonsWare Jun 07 '22 at 13:43
  • Ok yes, this is true. But still: The operating system always shows a dialog that asks the user for permissions. If the user rejects this request, the only way to enable the permission again, is to open the settings as described in https://developer.android.com/guide/topics/connectivity/wifi-suggest#change-approval. Is there any way to open this view programmatically? – Raman Jun 07 '22 at 22:43
  • I do not know. None of those `Settings` `Intent` actions seem better than the one that you tried. – CommonsWare Jun 07 '22 at 22:54
  • I have added a recording that shows which menu I want to open. The `Intent` that I have used in my code opens a wrong menu. In this case the use would need to navigate back to open a different settings menu. – Raman Jun 08 '22 at 08:01

0 Answers0