Android Question hardware state

khosrwb

Active Member
Licensed User
Longtime User
Hi:D
I will to know ( WIFI , Bluetooth , Data , NFC ,.....) state (( on or off )) , in all time. (( I need to service ))
sample: if wifi turned on then show me a massage box.:D

excuse me if my Language is bad:oops:
 
I will know hardware state (( when chenged state , show me a massage )).
I use from toggle library but with this library I can toggle on or off .
actually I can't listen the hardware state.:(
I need to listen the hardware state.:D
 
Upvote 0
actually I can't listen the hardware state.:(
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.

So i believe you CAN check the state....
 
Upvote 0
So i believe you CAN check the state....

how can I use from this library in service?
I will ,when chenge hardware state, I know that.((this is important for me )).
with toggle library , I can check in this time , but , I need to check all time (( any time )). (( of course this is my think )) if this is mistack , please tell me how can I use from them.
thanks to all
thanks
 
Upvote 0
See this you LAZY boy!

Please remind me to NOT answer to your Threads anymore...

LogCat connected to: 05157df57d72d204
--------- beginning of main
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (mysvc) Create **
AirplaneMode=false
Bluetooth=false
DataConnection=false
GPS=false
RingerMode=2
isScreenOn=true
WIFI=true
** Service (mysvc) Start **
** Activity (main) Pause, UserClosed = false **
** Service (mysvc) Destroy **
 

Attachments

Upvote 0
donmanfred
I use your app on emulator-5554 , but your app only worked for First Run
and for second and more time don't work. you can see on under pictures
SEE these pictures :


excuse me, that I could not properly explain.
But I do not want you to tell me lazy boy. please
I try to make beter
 

Attachments

  • 1.PNG
    1.PNG
    139.6 KB · Views: 395
  • 2.PNG
    2.PNG
    138.7 KB · Views: 370
  • 3.PNG
    3.PNG
    139.4 KB · Views: 374
Upvote 0
I use your app on emulator-5554
Use a real device! The emulator is slow and unreliable.

but your app only worked for First Run
and for second and more time don't work
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (mysvc) Create **
AirplaneMode=false
Bluetooth=false
DataConnection=false
GPS=false
RingerMode=2
isScreenOn=true
WIFI=true
** Service (mysvc) Start **
** Activity (main) Pause, UserClosed = false **
** Service (mysvc) Destroy **
** Activity (main) Resume **
** Service (mysvc) Create **
AirplaneMode=false
Bluetooth=false
DataConnection=false
GPS=false
RingerMode=2
isScreenOn=true
WIFI=true
** Service (mysvc) Start **
** Activity (main) Pause, UserClosed = true **
** Service (mysvc) Destroy **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Service (mysvc) Create **
AirplaneMode=false
Bluetooth=false
DataConnection=false
GPS=false
RingerMode=2
isScreenOn=true
WIFI=true
** Service (mysvc) Start **
** Activity (main) Pause, UserClosed = true **
** Service (mysvc) Destroy **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Service (mysvc) Create **
AirplaneMode=false
Bluetooth=false
DataConnection=false
GPS=false
RingerMode=2
isScreenOn=true
WIFI=true
** Service (mysvc) Start **
** Activity (main) Pause, UserClosed = true **
** Service (mysvc) Destroy **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Service (mysvc) Create **
AirplaneMode=false
Bluetooth=false
DataConnection=false
GPS=false
RingerMode=2
isScreenOn=true
WIFI=true
** Service (mysvc) Start **
** Activity (main) Pause, UserClosed = true **
** Service (mysvc) Destroy **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Service (mysvc) Create **
AirplaneMode=false
Bluetooth=false
DataConnection=false
GPS=false
RingerMode=2
isScreenOn=true
WIFI=true
** Service (mysvc) Start **
** Activity (main) Pause, UserClosed = true **
** Service (mysvc) Destroy **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Service (mysvc) Create **
AirplaneMode=false
Bluetooth=false
DataConnection=false
GPS=false
RingerMode=2
isScreenOn=true
WIFI=true
** Service (mysvc) Start **
** Activity (main) Pause, UserClosed = true **
** Service (mysvc) Destroy **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Service (mysvc) Create **
AirplaneMode=false
Bluetooth=false
DataConnection=false
GPS=false
RingerMode=2
isScreenOn=true
WIFI=true
** Service (mysvc) Start **
** Activity (main) Pause, UserClosed = true **
** Service (mysvc) Destroy **
I´ve started the app. Look at the log and quit the app. Start it again...
Over and over. Everytime it works for me.
 
Last edited:
Upvote 0
Use a real device! The emulator is slow and unreliable.

I´ve started the app. Look at the log and quit the app. Start it again...
Over and over. Everytime it works for me.

I run on Sony xperia Z1 , but don't work and no action on the log
 
Upvote 0
I think what khosrwb wants is something that will generate an event when the state changes. Something along the lines of
Code:
'example only, will not work
Sub Wifi_StateChange(State as Boolean)
    If State = True Then
        Log("Wifi was just turned on")
    Else
        Log("Wifi was just turned off")
    End If
End Sub
I looked around and couldn't find anything like that. Maybe you could just create a service like DonManfred posted, but have it poll the Toggle Library every few seconds to see if anything changed.
 
Upvote 0
Then create a timer and do so! Where is the problem?

Earlier ou asked me how to do this (and how to do in a service) cause you are too lazy to look for the right properties.

Now you want a timer. Something complete different.

But yes, it will work with a timer too
 
Upvote 0
Does anyone have an idea?
I do not want to use the timer. becuse if I use from timer for check the hardware state ,
1.Some of Rom will be constantly filled.
2.The CPU will be constantly processor hardware state.
3.While the system will do it himself.
 
Upvote 0
I'm not sure it is possible to do exactly what you want. Seems that settings changes do not generate events that apps can listen to. Just set a timer and call the appropriate sub when settings change.
Code:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim Ringer As Int
    Dim Toggle As Toggle
    Dim T As Timer

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.

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("Layout1")
    If FirstTime = True Then
    Toggle.Initialize
    Ringer = Toggle.RingerMode
    T.Initialize("timer",1000)
    T.Enabled = True
    End If

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
    If UserClosed = True Then T.Enabled = False

End Sub

Sub Timer_Tick
    If Toggle.RingerMode <> Ringer Then
        Ringer = Toggle.RingerMode
        DoRingerChange(Ringer)
       
    End If
End Sub

Sub DoRingerChange(R As Int)
    Select R
        Case Toggle.RINGER_MODE_NORMAL
            Log("Ringer Mode Normal")
        Case Toggle.RINGER_MODE_SILENT
            Log("Ringer Mode Silent")
        Case Toggle.RINGER_MODE_VIBRATE
            Log("Ringer Mode Vibrate")
        Case Else 
            Log("Unknown Mode")
    End Select
End Sub
 
Upvote 0
Back
Top