We've been using the WifiManager hidden API to enable Wifi tethering and create an access point. The problem now with API 26 on Android is that the tag @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
was added to the setWifiApEnabled
function and now that invocation returns false and the following log is printed:
W/WifiManager: PACKAGE_NAME attempted call to setWifiApEnabled enabled = true
Reading the new documentation, it says that the function is deprecated and will be removed in an upcoming release and to instead use ConnectivityManager#startTethering
if the caller has proper permission but this approach has the same problem with no TETHER_PRIVILEGED permissions. One other option presented on the documentation is the use of LocalOnlyHotspot
but this is no use to the project since the hotspot created has no Internet connectivity.
I've also tested with the startSoftAp
function from the hidden API but with no successful results since the following exception is thrown:
WifiService: Neither user 10164 nor current process has android.permission.NETWORK_STACK
Is there any workaround to activate a Wifi hotspot on newer APIs? I've also searched for alternatives to Wifi tethering but the only viable alternative seems to be Bluetooth tethering with the downside of only getting 3G speed. Wifi Aware and Wifi P2P were also considered but these have the problem of the Internet connectivity not being shared between the devices.
Any suggestions on how to approach this?
Set up an Automatic HotspotFrom Settings, tap Connections, and then tap Mobile Hotspot and Tethering. Tap Mobile Hotspot, tap Auto Hotspot, and then tap the switch to turn it on. Tap the switch next to Family sharing to let family members access your automatic hotspot if needed.
First and foremost, add permissions in your manifest file. These 4 permissions are required to make changes in your device network connectivity. Setup configuration to connect one specific wifi using WifiConfiguration. WifiConfiguration config = new WifiConfiguration();
Navigate to Settings > Network & internet > Hotspot & tethering. Here, you can select to share a connection via Wi-Fi, USB, or Bluetooth. For a Wi-Fi connection, tap Wi-Fi hotspot and toggle it on. The hotspot name will be displayed on this screen.
This has been answered many times. As, Snehashish Agarwal said, setWifiApEnabled() and startThethering() methods are private APIs. They are annotated with @hide which means they are private. Third party applications should not be invoking private APIs directly. There is no guarantee that they will work in future. As in your case.
Also, startLocalOnlyHotspot will not have the internet access. It is a local only hotspot to communicate between devices connected to the Wifi hotspot and this method will not have Internet access.
Currently, there are no official API call for enabling the Mobile hotspot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With