B4A Library ToggleLibrary

Hey everyone,

This is an improvement of my TurnGPS Library.
ToggleLibrary is great to use in homescreen widgets or just normal apps.
With ToggleLibrary, you can currently do the following:

- Bluetooth: Toggle, Enable, Disable, Check.
- Airplane Mode: Toggle, Enable, Disable, Check.
- WiFi: Toggle, Enable, Disable, Check.
- GPS: Toggle, Enable, Disable, Check.
- DataConnection** (GPRS,...): Toggle, Enable, Disable, Check.
- RingerMode: Toggle, Enable, Disable. (Vibrate, Silent or Normal)
- Change Brightness
- Change Mediavolume.
- Reboot, GotoSleep, UserActivity, isScreenOn

There might still be a few bugs. Please let me know.

* With check, I mean that you can check if it's enabled(true) or disabled (false)
** Depends on device

Attached are the library files.
No sample is added because it is all self-explanatory.

B4X:
Dim TGL As Toggle
TGL.Initialize()
TGL.TurnBluetoothOn



Tomas
 

Attachments

  • ToggleLibrary1.0.zip
    6.9 KB · Views: 3,918

lock255

Well-Known Member
Licensed User
Longtime User
I tried this library on my device 4.1.2:
GPS: does not work
Bluethoot: works

It would be nice that an B4A's expert release an update fix from this library with cool features!
 

Levisvv

Member
Licensed User
Longtime User
The Bluetooth toggle works great on my Galaxy 5 Android 4.4, but when I tried the GPS toggle, I get an error indicating that I need:
ACCESS_FINE_LOCATION

Does anybody know how I can add this permission? Is there a line I need to add to the Manifest?
I tried to add this but it caused an error: <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
 

Chris Williams

Member
Licensed User
Longtime User
Hello again, XverhelstX. I have created an app which makes use of your library. Prior to me uploading it to google play, I would like to know what I need to do to give you proper credit for your work. I have included a credits page that is in the app...
 

BarryW

Active Member
Licensed User
Longtime User
Hey everyone,

This is an improvement of my TurnGPS Library.
ToggleLibrary is great to use in homescreen widgets or just normal apps.
With ToggleLibrary, you can currently do the following:

- Bluetooth: Toggle, Enable, Disable, Check.
- Airplane Mode: Toggle, Enable, Disable, Check.
- WiFi: Toggle, Enable, Disable, Check.
- GPS: Toggle, Enable, Disable, Check.
- DataConnection** (GPRS,...): Toggle, Enable, Disable, Check.
- RingerMode: Toggle, Enable, Disable. (Vibrate, Silent or Normal)
- Change Brightness
- Change Mediavolume.
- Reboot, GotoSleep, UserActivity, isScreenOn

There might still be a few bugs. Please let me know.

* With check, I mean that you can check if it's enabled(true) or disabled (false)
** Depends on device

Attached are the library files.
No sample is added because it is all self-explanatory.

B4X:
Dim TGL As Toggle
TGL.Initialize()
TGL.TurnBluetoothOn



Tomas
Can you add NFC toogle on ur library...
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello,
I want to create a widget to switch on/off the data connection.
I wrote this simply code, but it doesn't work.
What's wrong?


B4X:
Sub Globals
Dim btOn, btOff As Button
Dim TGL As Toggle
End Sub

Sub Activity_Create(FirstTime As Boolean)
btOn.Initialize("btOn")
btOff.Initialize("btOff")

Activity.AddView( btOn, 1.4%x,  0.8%y, 27.8%x, 15.6%y) : btOn.Text = "ON" : btOn.Color = Colors.Green  
Activity.AddView(btOff, 1.4%x, 17.2%y, 27.8%x, 15.6%y) : btOff.Text = "OFF" : btOff.Color = Colors.Red

TGL.Initialize
End Sub

Sub btOn_click
TGL.TurnDataConnectionOn
End Sub

Sub btOff_click
TGL.TurnDataConnectionOff
End Sub
 

Cüneyt Gargin

Member
Licensed User
Longtime User
Hello. I have a Symbol (aka Motorola) TC55 device. It has a barcode imager on it. Can I turn it on and off with Toogle ? The device web site with intent info is : https://developer.zebra.com/thread/29606
 

Attachments

  • symbol_barcode.jpg
    symbol_barcode.jpg
    101.3 KB · Views: 230

peacemaker

Expert
Licensed User
Longtime User
Hi, All

Was the lib tested under Android8+ ?
Runtime permission for PERMISSION_ACCESS_COARSE_LOCATION?

I have error:
at "if...":
B4X:
    If Toggler.Bluetooth = False Then
        Toggler.TurnBluetoothOn
    End If

------------
upd: SOLVED:
B4X:
Sub Activity_Resume
    If rp.Check(rp.PERMISSION_ACCESS_COARSE_LOCATION) = False Then
        Dim a As String = "Bluetooth BLE requires this  PERMISSION_ACCESS_COARSE_LOCATION for searching devices, grant, please."
        txtLog.Text = a & CRLF & txtLog.Text
        If AlreadyWarned = False Then
            AlreadyWarned = True
            Msgbox(a, "WARNING:")
        End If
        rp.CheckAndRequest(rp.PERMISSION_ACCESS_COARSE_LOCATION)
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        If Result = False Then
            ToastMessageShow("BLE is unaccessible without this permission...", False)
            Return
        Else
            Starter.Toggler.Initialize
            'next toggle BT and go on...
        End If
    Else
        Starter.Toggler.Initialize
        'next toggle BT and go on...
    End If
....
 
Last edited:
Top