nickrussler / Android-Wifi-Hotspot-Manager-Class

Android Wifi Hotspot Manager Class
Apache License 2.0
271 stars 142 forks source link

android 8.0 can not open hotspot #21

Open huan51025 opened 6 years ago

myathinzar commented 6 years ago

use following to open hotspot on 8.0, Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.TetherSettings"); intent.setComponent(cn); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity( intent);

nickrussler commented 6 years ago

@myathinzar But that would require user action every time, which should be avoided..

The internal API that is used through reflection was deprecated and the new API seems to be rather difficult to access without root. There are some hints that it may be possible for Android 8.1:

https://groups.google.com/d/msg/automate-user/xy307m-hwvQ/NZERFRJSBgAJ

This seems to be a good starting point code wise: https://github.com/matejdro/TaskerTetherControl/blob/master/app/src/main/java/com/matejdro/taskertethercontrol/TetherSetupActivity.java https://github.com/matejdro/TaskerTetherControl/blob/master/app/src/main/java/com/matejdro/taskertethercontrol/TaskerReceiver.java