Android Code Snippet Start Local Hotspot

Status
Not open for further replies.
Starting from Android 8 there is a public API for starting a local hotspot.

Notes:
- The hotspot doesn't allow internet connection.
- The password and SSID are chosen randomly and cannot be changed.
- Debug it with USB debug mode as it will break B4A-Bridge connection.

SS-2018-10-26_09.36.57.png


Updates:

- Project was updated with changes required to support Android 13 devices with targetSdkVersion >= 33.
There is a new NEARBY_WIFI_DEVICES permission on Android 13+.
The location permission is required on Android 12-. See how it is declared in the manifest editor. Do note that if your app needs the location permission for other purposes then remove the snippet that limits the max version of that permission.
 

Attachments

  • Hotspot.zip
    14.6 KB · Views: 242
Last edited:

JohnC

Expert
Licensed User
Longtime User
Is the SSID and password chosen randomly every time this API is used (each session), or just the first time (and they stay the same between sessions).

If it changes each session, I'm curious how this ability is useful because any app using this API can not reliable connect to something else in a subsequent session if the SSID and password keeps changing. Can you provide a description of some application ideas that could use this API so I can better understand how this API can be useful?
 
Last edited:

FabioG

Active Member
Licensed User
Longtime User
great, but it would be nice to be able to change SSID and WiFi Password

Thanks!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Is the SSID and password chosen randomly every time this API is used (each session)
They change each time you start the hotspot. The SSID and password are managed by the OS.

Can you provide a description of some application ideas that could use this API so I can better understand how this API can be useful?
You want to connect two or more nearby devices that are not connected to the same network (maybe there is no network at all).

Create the local network. Use QR Generator to create a QR code with the SSID and password. Scan it from the other devices and connect to the new network.
 

fredo

Well-Known Member
Licensed User
Longtime User
...create a QR code with the SSID and password. Scan it from the other devices and connect to the new network.

This sounds very promising from the point of view of user-friendliness.

Would WriteFile of AsyncStreamsObject be the most reasonable way to transfer e.g. SQLlite files between devices?
 

JohnC

Expert
Licensed User
Longtime User
Create the local network. Use QR Generator to create a QR code with the SSID and password. Scan it from the other devices and connect to the new network.

Ah, that was the missing piece - I was wondering how can this be useful if two devices didn't know what the connection info was of the other device.

...And I see there is a B4A library for both generating and reading QR codes - nice!
 

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
There is a way to try without two android 8.0 devices?
Sorry if this question is too obvious.
 

avalle

Active Member
Licensed User
Longtime User
Starting from Android 8 there is a public API for starting a local hotspot.

I'd say there's no way without Android 8 then... However I think that only the host device must have it. The "client" device can be anything.
 

welu1805

Active Member
Licensed User
Longtime User
I tried to install this example in Android 5, 6, and 7 with B4A-Bridge and get a "Parse error: There was a problem while parsing the package". But my app should work in older Android versions AND in Version 8. In older versions I create the Hotspot with setWifiApState and in v 8 with this erxample. What is wrong?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Project was updated with changes required to support Android 13 devices with targetSdkVersion >= 33.
There is a new NEARBY_WIFI_DEVICES permission on Android 13+.
The location permission is required on Android 12-. See how it is declared in the manifest editor. Do note that if your app needs the location permission for other purposes then remove the snippet that limits the max version of that permission.
 
Status
Not open for further replies.
Top