#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private rp As RuntimePermissions
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private NativeMe As JavaObject
Private status As String=""
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("1")
NativeMe.InitializeContext
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
If Permission = rp.PERMISSION_ACCESS_FINE_LOCATION Then
If status="ON" Then
NativeMe.RunMethod("turnOnHotspot",Null)
else If status="OFF" Then
NativeMe.RunMethod("turnOffHotspot",Null)
End If
End If
End Sub
Sub btn_on_Click
status="ON"
rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
End Sub
Sub btn_off_Click
status="OFF"
rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
End Sub
#If java
import java.lang.*;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Build;
import android.os.Handler;
import android.content.Context;
import android.os.Message;
import android.util.Log;
import java.io.IOException;
import java.lang.reflect.Method;
int sdk = android.os.Build.VERSION.SDK_INT;
public WifiManager.LocalOnlyHotspotReservation mReservation;
public void turnOnHotspot() {
WifiManager manager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
manager.startLocalOnlyHotspot(new WifiManager.LocalOnlyHotspotCallback() {
@Override
public void onStarted(WifiManager.LocalOnlyHotspotReservation reservation) {
super.onStarted(reservation);
BA.Log("Wifi Hotspot is on now");
mReservation = reservation;
}
@Override
public void onStopped() {
super.onStopped();
BA.Log("onStopped: ");
}
@Override
public void onFailed(int reason) {
super.onFailed(reason);
BA.Log("onFailed: ");
}
}, new Handler());
}
public void turnOffHotspot() {
if (mReservation != null) {
mReservation.close();
}
}
#End If