Android Code Snippet Start Local Hotspot

Discussion in 'Code Snippets' started by Erel, Oct 26, 2018.

Thread Status:
Not open for further replies.
  1. Erel

    Erel Administrator Staff Member Licensed User

    Starting from Android 8 there is a public API for starting a local hotspot.

    - 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.


    Project is attached. Don't miss the two permissions added in the manifest editor.

    Attached Files:

  2. JohnC

    JohnC Well-Known Member Licensed 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: Oct 26, 2018
    f0raster0 likes this.
  3. FabioG

    FabioG Active Member Licensed User

    great, but it would be nice to be able to change SSID and WiFi Password

  4. DonManfred

    DonManfred Expert Licensed User

  5. Erel

    Erel Administrator Staff Member Licensed User

    They change each time you start the hotspot. The SSID and password are managed by the OS.

    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 likes this.
  6. fredo

    fredo Well-Known Member Licensed User

    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?
  7. Erel

    Erel Administrator Staff Member Licensed User

    No. You shouldn't use AsyncStreamsObject at all. However your question is not related to this thread.
    fredo likes this.
  8. JohnC

    JohnC Well-Known Member Licensed User

    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!
  9. Eme Fibonacci

    Eme Fibonacci Well-Known Member Licensed User

    There is a way to try without two android 8.0 devices?
    Sorry if this question is too obvious.
  10. avalle

    avalle Active Member Licensed User

    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.
    Eme Fibonacci likes this.
  11. Erel

    Erel Administrator Staff Member Licensed User

    Correct. The other device can be any wifi supported device. Including iPhone, ESP8266, PC and any other device you can think of.
    Eme Fibonacci likes this.
  12. welu1805

    welu1805 Active Member Licensed 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?
  13. Erel

    Erel Administrator Staff Member Licensed User

    The minSdkVersion in the example is set to 26. Change it as you need.
Thread Status:
Not open for further replies.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice