Android 6.0.1 couldn't enable wifi hotspot programmatically

前端 未结 5 1766
孤城傲影
孤城傲影 2021-02-09 02:20

When I tried to enable wifi tethering from the following code it throws the exception

java.lang.reflect.InvocationTargetException at java.lang.reflect.Method

5条回答
  •  既然无缘
    2021-02-09 03:05

    Set target SDK version 21 and ask for write_settings permission in your activity. Also add android.permission.WRITE_SETTINGS permission in manifest.

    if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                    Manifest.permission.WRITE_SETTINGS)){
    
    }else {
        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.WRITE_SETTINGS},
                121);
    }
    

    For more details please visit http://developer.android.com/training/permissions/requesting.html

提交回复
热议问题