Android Question Please help: Hotspot for Android error in my java code

welu1805

Active Member
Licensed User
Longtime User
Hi all, need help because my Java knowhow is not good.

In this article is code to start the hotspot in Android 8. This is done in a service called "starter".

https://www.b4x.com/android/forum/threads/start-local-hotspot.98664/

I want to put the code from starter to a class called clsHotspotOreo.

B4X:
Sub Class_Globals
    Public rp As RuntimePermissions
    Private WifiManager As JavaObject
    Private Callback As JavaObject
    Public HotspotReservation As JavaObject
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    WifiManager = ctxt.RunMethod("getSystemService", Array("wifi"))
    Callback.InitializeNewInstance(Application.PackageName & ".clsHotspotOreo$MyHotspotCallback", Null)
End Sub

Public Sub StartHotspot
    WifiManager.RunMethod("startLocalOnlyHotspot", Array(Callback, Null))
    Wait For Hotspot_Started (Success As Boolean, Reservation As Object)
    If Success Then
        HotspotReservation = Reservation
    End If
    CallSub(Main, "StateChanged")
End Sub

Public Sub StopHotspot
    If HotspotReservation.IsInitialized Then
        HotspotReservation.RunMethod("close", Null)
        Dim HotspotReservation As JavaObject
    End If
    CallSub(Main, "StateChanged")
End Sub

#if Java
import android.net.wifi.*;

public static class MyHotspotCallback extends WifiManager.LocalOnlyHotspotCallback {
  @Override
  public void onFailed(int reason) {
        BA.Log("failed: " + reason);
        clsHotspotOreo.processBA.raiseEventFromUI(this, "hotspot_started", false, null);   
    }
    
  @Override
  public void onStopped() {
         BA.Log("OnStopped");
     }
    
  @Override
  public void onStarted(WifiManager.LocalOnlyHotspotReservation reservation) {
       BA.Log("onStarted");
       clsHotspotOreo.processBA.raiseEventFromUI(this, "hotspot_started", true, reservation);
  }
}
#End If

In the original Java code in the @override are lines "starter.processBA.raiseEvebtFromUI ..." because the service is called "starter". I replaced "starter" by "clsHotspotOreo" because my class is called "clsHotspotOreo". This is probably wrong because I get a compile error:

Compiling generated Java code. Error
B4A line: 31
End Sub
javac 1.8.0_131
src\de\wedersoft\musicbook\clshotspotoreo.java:171: error: package clsHotspotOreo does not exist
clsHotspotOreo.processBA.raiseEventFromUI(this, "hotspot_started", false, null);

In Main I declared:

B4X:
Dim OreoHotspot As clsHotspotOreo
OreoHotspot.Initialize

Because my Java is not good, what is wrong?
Lutz
 

welu1805

Active Member
Licensed User
Longtime User
I have several classes for client and server settings, e.g. one for hotspots until Android 7. Now I want to create a new class for hotspot with Android 8.
 
Upvote 0

Similar Threads

Top