broadcastreceiver

How to refresh a ListView from a BroadcastReceiver?

爷,独闯天下 提交于 2020-01-13 12:52:32
问题 If I call notifyDataSetChanged() on the custom adapter associated to my ListView, all the views should refresh themself ( getView() will be called). Now I have a BroadcastReceiver that is listening to an event. When the event fires, the ListView must be refreshed. How can I achieve this? Thanks! 回答1: If you refresh listview from receiver you'll have code like this: BroadcastReceiver br; public final static String BROADCAST_ACTION = "BROADCAST_ACTION"; br = new BroadcastReceiver() { public

How to refresh a ListView from a BroadcastReceiver?

和自甴很熟 提交于 2020-01-13 12:52:17
问题 If I call notifyDataSetChanged() on the custom adapter associated to my ListView, all the views should refresh themself ( getView() will be called). Now I have a BroadcastReceiver that is listening to an event. When the event fires, the ListView must be refreshed. How can I achieve this? Thanks! 回答1: If you refresh listview from receiver you'll have code like this: BroadcastReceiver br; public final static String BROADCAST_ACTION = "BROADCAST_ACTION"; br = new BroadcastReceiver() { public

How to distinguish the screen on/off status while incoming call?

喜夏-厌秋 提交于 2020-01-13 11:35:10
问题 My app uses the TelephonyManager.ACTION_PHONE_STATE_CHANGED for some actions. But I want a different action while the phone rang when the user was present (screen was on) and different action when the user was not present (screen was off). I tried the isScreenOn() method just in the beginning of onReceive (because when screen is off and there is incoming call, the screen stays off for a short while). No luck however - sometimes it works, sometimes not. The broadcast is asynchronous with the

XMPP events on Android

…衆ロ難τιáo~ 提交于 2020-01-13 03:19:26
问题 I'm trying to develop a background process that intercepts a XMPP message and performs an action, I'm using asmack as the main XMPP library. I presume I need a broadcastReciever that responds to a specific intent. The question is how to raise the intent? It must be possible as this functionality is present in the google talk client. many thanks in advance. 回答1: If you really want to achieve this behavior, you might think about a persistent background service running the asmack XMPP client.

Detect outgoing calls, issue with a real device

末鹿安然 提交于 2020-01-11 09:58:05
问题 I have a strange problem. To detect outgoing calls I have registered a broadcast receiver for android.intent.action.PHONE_STATE . When the state becomes OFFHOOK, then a conversation is started. It seems working on emulator: the debugger in fact reaches some code while it doesn't work on real device (Acer Liquid). Is it possible? Which is a way to detect outgoing calls? 回答1: Well, if it works on the emulator, I would expect it to work on the device. You might registering a PhoneStateListener

Android - Bluetooth device connected broadcast

萝らか妹 提交于 2020-01-11 07:47:12
问题 I want to have a broadcast receiver listening for BT devices connecting. Could anybody tell me which broadcast I have to listen to? I tried android.bluetooth.device.action.ACL_CONNECTED but it doesn't seem to work. Thank you. 回答1: If you are looking whether the device is "connecting" then you'd want android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED However, this does not get triggered when the device is STATE_CONNECTED. So what I did was when the state is connecting, to send a

How to ensure PeriodicWorkRequests are called on device reboot on Android N and upwards

走远了吗. 提交于 2020-01-11 07:25:10
问题 I recently tried to use the WorkManager 's PeriodicWorkRequest s as a surefire way of getting user location updates periodically in the background. The library met my requirements and this particular detail got my attention: Guarantees task execution, even if the app or device restarts Having implemented and tested it, I tried rebooting my device and noticed the Log message and App Notification never showed up. Naturally, I did some research and stumbled upon this: PeriodicWorkRequest not

Save data in Broadcast receiver

Deadly 提交于 2020-01-09 11:25:27
问题 I'd like to maintain a hash table in a broadcast receiver. If I understand BroadcastReceiver's life cycle currently it could get killed wiping out my member variables. What would be the ideal strategy for retrieving a hash table from a previous run of onReceive in the BroadcastReceiver? 回答1: There are two ways to use a BroadcastReceiver , and you did not indicate which you are using. One for a receiver registered by some other component -- like an Activity -- via registerReceiver() . This

Notification deleteIntent does not work

為{幸葍}努か 提交于 2020-01-09 10:07:22
问题 I've read several questions concerning similair issues, but they do not provide me with the solution. In my Android app I fire off a notification (in the Application class to be specific, which is actually started from a C2DM push event). I then want to receive an Intent when the "clear all" button is pressed on the notifications: notification.deleteIntent = PendingIntent.getService(this, 0, new Intent(this, NotificationDeleteReceiver.class), 0); In my NotificationDeleteReceiver.class I got

Notification deleteIntent does not work

独自空忆成欢 提交于 2020-01-09 10:04:34
问题 I've read several questions concerning similair issues, but they do not provide me with the solution. In my Android app I fire off a notification (in the Application class to be specific, which is actually started from a C2DM push event). I then want to receive an Intent when the "clear all" button is pressed on the notifications: notification.deleteIntent = PendingIntent.getService(this, 0, new Intent(this, NotificationDeleteReceiver.class), 0); In my NotificationDeleteReceiver.class I got