broadcastreceiver

Are Android's BroadcastReceivers started in a new thread?

佐手、 提交于 2019-11-27 18:59:02
If I have an inner class that extends BroadcastReceiver within my Service class, should I care about synchronization, when the BroadcastReceiver class reads/writes to objects from the Service class? Or to put it in another way: Are BroadacstReceiver 's onReceive() Methods started in an extra thread? Nick Pelly The onReceive() method is always called on the main thread (which is also referred to as "UI thread"), unless you requested it to be scheduled on a different thread using the registerReceiver() variant: Context.registerReceiver(BroadcastReceiver receiver, IntentFilter filter, String

How to use registerReceiver method?

故事扮演 提交于 2019-11-27 18:42:23
I want to use dynamically registered BroadcastReceiver that has a reference to an Activity so it can modify its UI. I am using Context.registerReceiver() method but receiver's onReceive() method is never called. Here is the sample code showing the problem: package com.example; import android.app.Activity; import android.app.IntentService; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; public class

Is it possible to run service in android platform continuously even after locking the device?

[亡魂溺海] 提交于 2019-11-27 18:36:18
问题 We have been working on developing service for android platform. In our service we need to send GPS data (Lat and Long) of device to some external REST service after every one minute. It is running fine for almost 15 minutes after locking of device. But after that it does not send any data. After unlocking the device, it start again to send data over REST service. My Code So far public class MainActivity extends AppCompatActivity { private PendingIntent pendingIntent; private PowerManager

How to handle the Firebase notification when app is in foreground

柔情痞子 提交于 2019-11-27 18:34:51
I have integrated Firebase Cloud Messaging with my application. When I sent a notification from the Firebase console, if the app is in background or not opened I receive successfully the notification, otherwise if the app is in foreground or opened, I did not receive it. All suggestions are appreciated. Shivam Bhusri When app is in foreground, notifications are not generated themselves. You need to write some additional code. When message is received onMessageReceived() method is called where you can generate the notification. Here is the code: public class MyFirebaseMessagingService extends

android - “Exported receiver does not require permission” on receivers meant to receive from system services

*爱你&永不变心* 提交于 2019-11-27 18:27:10
I have some receivers declared in my AndroidManifest : <!-- no warning --> <receiver android:name=".receivers.TriggerMonitoringBootReceiver" android:enabled="false"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> <!-- no warning --> <receiver android:name=".receivers.ScanResultsReceiver" android:enabled="false"> <intent-filter> <action android:name="android.net.wifi.SCAN_RESULTS" /> </intent-filter> </receiver> <!-- warning : Exported receiver does not require permission--> <receiver android:name=".receivers.BatteryMonitoringReceiver

Android: Detect another application has started playing audio

故事扮演 提交于 2019-11-27 18:24:19
My music application constantly plays music in the background, however I'd like to be able to detect when another application starts playing audio (such as the YouTube app) so I can pause/mute/stop the audio in my application. This will allow a user to continue browsing the web whilst listening to music, but then if they wish to watch a video at any point, they can do so without audio conflict. One solution might be to listen for a broadcast which states when an application begins using the AudioManager. Does such an Intent Action exist? Edit: As in the answer provided below, there appears to

Android Activity with no GUI

空扰寡人 提交于 2019-11-27 18:22:09
I have created a activity that is only meant to be launched from a link (using a intent filter.) I do not want this activity to have a GUI - I just want it to start a service and put a notification in the bar. I have tried to put the intent filter for the link in my service, but that does not work. Is there a better thing to do this that will answer to intent filters - or can I just make my activity not have a GUI? Sorry if I'm being confusing, Isaac Reto Meier Your best bet would seem to be using a BroadcastReceiver . You can create a new BroadcastReceiver that listens for the Intent to

Is it possible to write an Android broadcast receiver that detects when the phone wakes up?

笑着哭i 提交于 2019-11-27 18:21:22
问题 I want to figure out how to detect when the phone wakes up from being in the black screen mode and write a handler for that event. Is that possible? It seems like this would be something a Broadcast Receiver should handle? Or is there a better or more proper way? 回答1: If you have a Service that it active you can catch these events with registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // do something } }, new IntentFilter(Intent

Detect the end of an answered incoming call by user in android? (not declined)

北城以北 提交于 2019-11-27 18:06:41
问题 In my android application, I have created a BroadcastReceiver that detects incoming call; my code is running very well. If there is an incoming call ( EXTRA_STATE_RINGING ), I can see my incommingNumber in the logcat, also when the user answered the call ( EXTRA_STATE_OFFHOOK ) I used shared preferences to store incoming number (String) in ringing state , then get it in Off HOOK state. This is my code, it works perfectly: public class IncomingCallReceiver extends BroadcastReceiver { @Override

How To Test BOOT_COMPLETED Broadcast Receiver In Emulator

旧时模样 提交于 2019-11-27 17:58:59
I want to check the BROADCAST RECEIVER with Action BOOT_COMPLETED in the emulator . Is there any way to check that broadcast receiver in emulator ? How can i restart emulator to check that receiver ? is there any direct command? Thanks in advance. There is no Power Button in Emulator like Devices have,So To stop an emulator instance, just close the emulator's window. And To Start/Restart it Start from AVD Manager of Eclipse and Your BroadcastReceiver with BOOT_COMPLETE action will get called for sure You can start AVD another way also, From CMD go to Tools of AndroidSDK and give this commmand