I have a requirement to always have mobile data "ON" in android. How to implement it through code ? do i need to register for some broadcast receiver or something like that ?
You can't control when mobile data is on. You can only register a receiver to be told when it changes.
Yes you need the register for CONNECTIVITY_CHANGE reciever,
You can use my connectivity change helper to do this,
https://github.com/talhakosen/ConnectionListener
Maybe the solution could b to when user select always on: if already not connected, connect and if connected register receiver to listen for state change, on disconnect state receive, connect again..please suggest this approach is right?
Related
I am developing and app which uses bluetooth communication. I need to have an icon to show if bluetooth is connected or not at all times in the action bar. How can I implement this?
The check on BluetoothSocket mmSocket
if(mmSocket==null)
can be called in methods. Is there a way to check this continuously while the app is running ?
I might give you some help but I will not explain all the thing to you. You have to search a little.
If you don't understand something, Google it or search it on google dev website :)
There is a broadcast here BluetoothAdapter.ACTION_STATE_CHANGED
Register that broadcast and look at the documentation to know what in the BroadcastReceiver will tell you if the bluetooth is ON or OFF.
Please don't forget to unregister your receiver when your activity is paused / destroyed.
Because the broadcast will not tell you on each first launch of the activity if the Bluetooth is ON/OFF (because it is only fired when Bluetooth state changed!), you might want to look at this solution to check the Bluetooth connection state on the fly
How to check if bluetooth is enabled programmatically?
I want my app to be fire any time device connected to internet to pars xml and notify user in notification panel.
Plz let me know how to do .
You need a broadcast receiver to be notified when the internet connection state is changed. Take a look at this and this.
I am going to implement Download Queue for my application. One of its feature will be when Network get connected or disconnected. I want to notify my QueueManger(Service) to update items status and stop.
I know use of Broadcast Receiver and how to use it. My question is if my application is stooped (finished) will broadcast receiver will work? Will it notify application or not?
If not is there any way to achieve this functionality even when application is stooped.
If you register your receiver in the XML instead of programmatically, then it should be able to catch these even when the program is not running.
See question, same solution applies Intent action for network events in android sdk
If you have defined your broadcast receiver as <receiver> in AndroidManifest.xml and listening for android's default action strings, then Yes, it will work.
Otherwise, I would recommend you to make use of Service. It can run silently in the background and do all the logic you want. Your service can even be provoked automatically when the phone is restarted (if you code correctly).
My app is for tracking, have to send to php all I got. I have methods such as postData to php, my location listener class and getMyPhoneNumber. My question is what should I choose to develop that app? I have read Android Service and Broadcast Receiver documents and I still can't figure it out. Which one of them is more suitable?
PS, Thanks in advance
suitable depends upon requirment .
if you want to receive particular broadcast or in other words want to do some operation on specific event like location change use broadcase Reciever while if you want something to happen consistently use srvice .
service will always run (in background) while BroadCastReceiver will receive related broadcast and run
In my android application, I'm looking for a particular bluetooth device. When I found a bluetooth device, I check if it's the one I'm looking for and if it is, I call cancelDiscovery();
My question is : If I cancel the discovery, will I still receive the ACTION_DISCOVERY_FINISHED broadcast or not ?
Thank you !
Yes, as soon as you cancel the discovery ACTION_DISCOVERY_FINISHED broadcast will receive it.