I want to use my device like a camera in my house, and i want to enable/disable it times to times through Wi-Fi when needed! How can i do that? I know that when device in sleep mode, t disables wifi, but maybe there is some another feature to disable screen or something else.
I didnt tried it so far but you would need to change Android-settings to let wifi turned on while the device is in sleep mode. So you have a connection running. Then you should create a background-service with a callback function. Everything what you need should be described here.
https://developer.android.com/training/best-background.html
Related
We are making a SIP-related solution and I am requested to compose an app on a customized android pad(4.4.*). Unluckily, the pad is from 3rd party and accordingly we hardly do further jobs on the framework or driver......
On the Pad, a LAN port is designed over USB and we plan to access network via LAN. Besides, no power key is populated on the cover.....
Now the question is: Since the pad sleeps, the LAN connection is stopped soon. I fully understand it's a normal behavior that android conducts. I am trying to acquire known wake lock(partial or WIFI lock) to stop USB controller from sleeping ... but, currently, little progress. is there any usb-related wake lock, just like wifi lock ?
I have solved the problem from the perspective of HW .... I am not sure the solution is really meaningful to the current topic. But I think that sharing the idea with you is the major goal of the forum running.
a MOS component is added along the power line controlling Screen. Then I manipulate the connection/disconnection by sending command to MCU....
Based on my experiences , it is really hard to extend functionality on a poor quality of pad ... poor post-sales support.......
Hope you it's helpful to you.
I wan't to check if the user is operating the phone while a call is being made by using device's sensors and GPS.
I need to check if we are in hand free mode because in that case I should hear noise but may not see any movements or rotation.
I tried looking in android.telephony but found nothing. Also tried my good old friend google and no luck. Is it even doable?
Thanks!
Here you go. Your problem can be divided into 4 steps. Plus you dont need any sensors or GPS to achieve this.
1) Try to get connected Bluetooth Device list, via BluetoothAdapter class.
2) Check device class, via BluetoothDevice's APIs.
3) If you see Phone is connected to Bluetooth Device with capabilities like A2DP(audio) etc. Then you will know phone is in handsfree mode.
4) also try to find out phone_state of the phone. It shouln't be Idle, if you just want to check in state of making/receiving/during call.
I'm designing an app which uses wifi for certain purposes. I want to prevent the user from turning the wifi radio off from the wifi settings of the device while my application is running and the device connected to my wifi network. Is there a chance this can be done? I read in WifiManager.WifiLock and they say this: "Note that WifiLocks cannot override the user-level "Wi-Fi Enabled" setting, nor Airplane Mode. They simply keep the radio from turning off when Wi-Fi is already on but the device is idle." Can it be done somehow??
You cannot prevent the user from turning off the wifi from your code. Even if you find out an evil way to do it , you should not try to do it. If I find out any app in my phone does evil things like these, I will just remove the app. I am sure most people are just like me.
If you really want to do it for some reason , perhaps you could tell us what the scenario is and we might be able to help you with a different solution you havent thought about
when android phone is in SLEEP State 0r Locked State What is the state of WIFI ?
is it active or not?
It's depend on application. By default in Sleep mode wifi state is inactive. Application need to take a wifi lock to keep it acive.
It depends on many factors, including those that others have metioned:
In your android settings, wireless settings, advanced settings- there is a wifi sleep policy which can somewhat answer your question.
However, an application (with the appropriate permission) can change this setting or temporarily change it to bypass the setting.
"Sleep" is pretty vague because some consider this when your display is turned off, however a device actually has different levels of sleep, and deep sleep. Deep sleep doesn't kick in as soon as the display is off, and often these rules are referring to deep sleep.
Applications can also obtain a wifi lock (with the appropriate permission) which will wake up the Wi-Fi radio even though the phone is in deep sleep.
Must be active, I've downloaded stuff from the Market place whilst my phone (HTC Desire) has gone to sleep, and the download has finished the next time I unlock (wake) it.
By default, Wifi sleep policy is "Sleep on screen idle".
With this policy, is it possible for a Background Service at a later time to wake up Wifi using some API?
Am trying the following, but does not work:
When my Background Service wakes up, it calls "ConnectivityManager.getActiveNetworkInfo()" to get active network.
Since, the wireless is off on idle, I tried waking it up using "WifiManager.startScan" on a previously used Wifi connection.
But still dont get Wifi connectivity.
Any ideas?
I preferably do not want to change my sleep policy to "Never".
Thanks
Hemant
There are no real simple solutions for this. To with a high probability ensure you have WIFI connectivity when the phone/screen goes to sleep the best way is to turn it off. Look here for a lot of details - http://wififixer.wordpress.com/
It is important to realize that in sleep mode the Wifi enters a low power mode. This will become tricky then to programmatically check as it might have connectivity to the Wifi but the Wifi connection is too weak or too slow to complete the HTTP request and hence it times out. This would force you to also check the speed of the Wifi connectivity as well as you will have an active network but a pretty lousy one.
Proper handling of the escaping when timeout occurs for the HTTP call you make makes it ok to use but ultimately the only way to have a background thread constantly running to get data is only doable when you have the Wifi mode to never sleep.
It is tricky and not the best way I know. :-( It is however the only path I have found which is reliable enough.