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,921

bluedude

Well-Known Member
Licensed User
Longtime User
Would you be interested to do some paid/sponsored work? Je spreekt ook Nederlands volgens mij?
 

Ronny

Member
Licensed User
Longtime User
No Reeboot

Thanks for this lib. :)

I can't get the "Reboot" to work. The program crash with the included error. I suspect this wil only work on rooted devices?
B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim t As Toggle
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.
   Dim RebootButton As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("main_layout")
   t.Initialize
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub RebootButton_Click
   t.Reboot
End Sub


java.lang.ClassCastException: android.media.AudioManager
at com.rootsoft.togglelibrary.ToggleLibrary.Reboot(ToggleLibrary.java:484)
at no.edev.reboot.main._rebootbutton_click(main.java:309)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:105)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:89)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:49)
at android.view.View.performClick(View.java:2408)
at android.view.View$PerformClick.run(View.java:8816)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
 

glouie

Member
Licensed User
Longtime User
Hi Tomas,

I tried using your library for Bluetooth, Airplane mode, and GPS - all of which work wonderfully.

Thank you!
 

glouie

Member
Licensed User
Longtime User
Reboot

I just tested the reboot function and also get the same error that Ronny mentioned.
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
I'm not sure if you did it like this, but I have your wifi toggle library and was wondering if you could make it raise an event when wifi (and the other hardware) finishes turning on, so you dont have to keep polling it.

And all hardware would go through a single event.

ie: _HardwareOnline(HardwareType as Int)
HardwareType = 0 for wifi, 1 for Bluetooth, etc.
 
Last edited:

manios

Active Member
Licensed User
Longtime User
I tested the Bluetooth functions, works well.:)
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
I'm not sure if you did it like this, but I have your wifi toggle library and was wondering if you could make it raise an event when wifi (and the other hardware) finishes turning on, so you dont have to keep polling it.

And all hardware would go through a single event.

ie: _HardwareOnline(HardwareType as Int)
HardwareType = 0 for wifi, 1 for Bluetooth, etc.

Ok, I will take a look at it.

Tomas
 

alibaba

Member
Licensed User
Longtime User
Toggle GPS Problem with 2.3

Toggle GPS work perfect with Android 2.2 but with Android 2.3 i have on 3 Galaxy Tabs the Problem that i can't activate the GPS if the the User has it turned Off in the pull down menu, this works on 2.2 but not with 2.3 dit anyone have a Solution for this ?
 

KikeCentolo

Member
Licensed User
Longtime User
Do not work on ICS

Toggle GPS work perfect with Android Gingerbread but with Android ICS i can't activate the GPS dit anyone have a Solution for this ?
Thanks:)
 

rfresh

Well-Known Member
Licensed User
Longtime User
I too cannot get the .Reboot to work...I'm getting errors too...Droid2...
 

rfresh

Well-Known Member
Licensed User
Longtime User
On the Droid2 the .TurnOnWiFi works and the .TurnGPSOn works too...my OS shows as 2.3.x
 

Bardill

Member
Licensed User
Longtime User
The TurnAirPlaineModeOff not work on HTC Sensation or HTC ONE on ICS and older 2.3.x

It Works on Samsung S2

Is this a bug from HTC?
 

rfresh

Well-Known Member
Licensed User
Longtime User
Just so I'm clear, the DataConnection boolean is my celluar connection to the internet on my phone?

I have a Droid3 with a cellular connection to the internet and I have turned off WiFi and TGL.DataConnection is false. I was expecting it to be true?

Update: Hmmm...now the DataConnection is True (which I was expecting it to be) but my FTP won't connect to my website to download a file. If I turn on the Droid3 WiFi, it will connect and download the file. Any thoughts?
 
Last edited:

GaNdAlF89

Active Member
Licensed User
Longtime User
when I try this:
B4X:
Dim t As Toggle
t.Initialize()
t.Reboot

I have this exception:
android.media.AudioManager cannot be cast to android.os.PowerManager

How can I resolve?
 

GaNdAlF89

Active Member
Licensed User
Longtime User
Sub ButtonV_Click
Dim tgl As Toggle
tgl.Initialize
tgl.Reboot 'error in this line
End Sub

java.lang.ClassCastException: android.media.AudioManager cannot be cast to android.os.PowerManager
at com.rootsoft.togglelibrary.ToggleLibrary.Reboot(ToggleLibrary.java:484)
at it.ticket.main._buttonv_click(main.java:877)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:158)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:154)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:54)
at android.view.View.performClick(View.java:3131)
at android.view.View$PerformClick.run(View.java:12035)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
 
Last edited:
Top