0

In Android M, I used code in How to create wifi tethering Hotspot in Android Marshmallow? to create hotspot, but it is not working.

I get error.:

java.lang.SecurityException: android.tutorial.hotspotcreation was not granted either of these permissions: android.permission.CHANGE_NETWORK_STATE, android.permission.WRITE_SETTINGS.

If I use that hotspot code.

The recommended way, is to use an intent:

startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));

Is there a way to create hotspot via code, without user-intervention?

Community
  • 1
  • 1
buttercup
  • 1,096
  • 16
  • 37

1 Answers1

1

As your error message clearly shows, you will have to add two permissions to your Manifest (or ask for them interactively on 6.0+):

  • CHANGE_NETWORK_STATE
  • WRITE_SETTINGS
Jonas Köritz
  • 2,606
  • 21
  • 33