I am trying to call the public android method getSSID() from a bash script? My objective is to return the currently connected SSID on the android device to a bash variable.
requirements:
- must run as non-root user
- must use only android baked in functions.
- AKA requires no additional app installs
- must run directly from a simple bash script.
Previously: I had been using the dumpsys command with grep to retrieve what I need but now it seems I need to be root for this to work, so I'm looking for a replacement for this concept.
$ dumpsys wifi | grep -i $grepwifi
So I found this public api...
https://developer.android.com/reference/android/net/wifi/WifiInfo.html
But I am not able to figure out how to get it to work. I have tried a couple options such as listed below without any luck.
$ am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiInfo.getSSID()
/system/bin/sh: syntax error: '(' unexpected
Or
$ am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiInfo.getSSID
Starting: Intent { act=android.intent.action.MAIN cmp=com.android.settings/.wifi.WifiInfo.getSSID }
Error type 3
Error: Activity class {com.android.settings/com.android.settings.wifi.WifiInfo.getSSID} does not exist.
I'm assuming that I am simply not putting the url together correctly. So I hoping that someone can point me to documentation on how these commands can be structured so that once I get past the ssid chalange I can continue to explore other public api's but if there is another easy way to retrieve wifi information from the device I would be grateful for any alternatives that work.