App: Wifi Hot-Spot on Oreo


I rooted my Pixel XL to try and fix the Trigger app’s refusal to turn on wifi hot-spotting automagically when I turn my car on. The reason it’s not working, I think, is that Trigger is borderline abandonware and has not been updated for Oreo’s new (lack of) exposure of hotspot function in WifiManager.

I wrote a little app (which turned out to be quite a lot of screwing around) to fix this. It runs in the background and provides a way to turn WiFi HotSpot off and on with Intents.

If you are simple instructions for setting up on Trigger – they’re here.

The source is still here on GitHub.

Once you’ve installed the app, you can turn on the Oreo device’s WiFi HotSpot (from another/ your application) with the action element route or data element route. To turn the hotspot off you replace the ‘on’ in all the code/links below with ‘off’.

Action Element

1
2
3
Intent intent = new Intent();
intent.setAction("com.fitc.wifihotspot.TURN_ON");
sendBroadcast(intent);

***EDIT 02/04/2018***
Time-old code above for broadcasting an intent does not work in Oreo. Oreo introduced an Implicit Broadcast Ban – more about that here
A (temporary?) workaround is listed on that same CommonsWare article:

1
2
Intent intent = new Intent("com.fitc.wifihotspot.TURN_ON");
sendImplicitBroadcast(this,intent);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
private static void sendImplicitBroadcast(Context ctxt, Intent i) {
PackageManager pm=ctxt.getPackageManager();
List matches=pm.queryBroadcastReceivers(i, 0);

for (ResolveInfo resolveInfo : matches) {
Intent explicit=new Intent(i);
ComponentName cn=
new ComponentName(resolveInfo.activityInfo.applicationInfo.packageName,
resolveInfo.activityInfo.name);

explicit.setComponent(cn);
ctxt.sendBroadcast(explicit);
}
}

Unfortunately,waht this means is that if you are using some third-party app where these is an option to broadcast implicit intents, then unless they have implemented this workaround (a something else which works), my app willnot work.

Data Element

1
2
3
4
Uri uri = new Uri.Builder().scheme("wifihotspot").authority("turnon").build();
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(uri);
startActivity(i);

The code above is the same as you would use for getting your app to open your default Android browser on whatever-website.

FYI, the data route uses that same stuff under-the-bonnet as what Android does with a hyperlink on a website. In fact, if you have installed the app on your phone and you are reading this in your browser on your phone, then clicking on wifihotspot://turnon SHOULD turn on your hotspot?!? Maaagic! Click  wifihotspot://turnoff and off it goes. Whoaaaa!!

EndNote

There were two hurdles I ran into. Too drunk to explain them in detail, but you can see how I overcame them in GitHub code::

  1. data element in an intent only picked up by ‘Browsers’ (which must be Activity), not my BroadcastReceiver (as I’d hoped)
  2. It’s a whole lot of pain getting at Oreo’s hotspot tethering – more here.