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.
Related
As we all know Broadcast receiver is not working anymore, kindly suggest me a better way to get this done.
Reccelly, I had used firebase to listen to event call incomming. Android system don't kill firebase service when it run in background. Now, I only know this way.
I'm new in android development, and need some help and guidance in triggering my notification in my application. I manage to read some documentation about BroadcastReceiver where in it broadcast an announcement and another app can receive that announcement and trigger something to happen(like popping out a notification). I tried doing it, wherein I have 2 (two) application in 1 (one) android device and it worked. But when I try separate the 2 (two) application and install it separately into 2 (two) android device and try to send the broadcast, the receiver didn't manage to receive the broadcast. Then I tried to do more research and saw that BroadcastReceiver is a "System-Wide" broadcast, means (correct me if I'm wrong) it will only work inside 1 (one) android device. So my question is now, is there anyway to make the BroadcastReceiver send the broadcast in the network so that if an android device with a receiver can receive the sent broadcast? if it's not possible, is there another way to trigger notification in 1 device using another device w/o using the FCM/GCM?
PS:
The reason why I don't want to use FCM/GCM is that I'm trying to do this in an adhoc network, wherein internet connection is not present. And I'm not sure how FCM/GCM will behave w/o the internet connection. I appreciate any help. Thanks you.
You can setup a server in a background service on one of the devices and send data to if from the other device, and then have that service create a notification when it gets data.
If you want the devices to automatically be able to discover each other try using the network discovery service. https://developer.android.com/training/connect-devices-wirelessly/nsd.html
I wonder how to scan periodically for bluetooth devices, even when app is closed? I tried to register receiver and tried not to unregister in onDestroy() method, with hope that it will countinue working in background.
But when i close the app it sends an error:
Are you missing a call to unregisterReceiver()?
And there are no more scanning. So, please, can someone tell me how to do this? Maybe it has to do something with services? Send me on the right path :)
You would want to create an Intent service that responds to the intent that you have in your filter (I apologize I do not remember the intent). This service would run each time that intent is broadcast.
Here are the docs to create an Intent Service
https://developer.android.com/training/run-background-service/create-service.html
What are you using to scan? If you're not using it, I believe you should be using the AlarmManager class. It will allow you to continuously perform a task without the app needing to be open. There are plenty of tutorials out there.
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 have a working broadcast receiver for C2DM, which normally works perfectly, but in some cases in the field, it just stops being invoked by the system. My question is:
Under what circumstances would Android suddenly stop sending intents to a particular application, even if the app is currently running?
Given that it works the majority of the time, I'm trying to figure out if there's some way for the broadcast receiver to "go bad" or the process be marked bad etc. I have verified that Google is happy with the C2DM (i.e. it's not rate-limited due to quota or anything like that).
I am having exactly the same problem and what helps me is toggling wifi on and off, when it reconnects it starts receiving again. For me this is only the case when using C2DM, not tested with other broadcastreceivers. I know that this is not really an exact answer to the problem.
There also happens to be a problem with C2DM not working very good over wifi. So are you using your wifi connection or mobile-internet? Try only using your mobile internet for a while and see if the receiver still stops receiving.
Let me know if one of these tips got you any further!
Dino
just change one line in manifest.
receiver android:name=".MyBoardCastReceiver" android:enabled="true"