broadcastreceiver

Broadcast Receiver on Android Oreo

北慕城南 提交于 2019-11-28 07:50:12
问题 I have a network change receiver class and it extends from broadcast Receiver, but I’m not pretty sure that it’s working in android Oreo, does Oreo support broadcast receiver, and if it doesn’t support, what’s the other way to do it 回答1: It's not supported in Oreo as manifest tag, you must have to register it at an Service/ Activity with context.registerReceiver(). Or you use the WorkManager to schedule something for specific network conditions. 回答2: Oreo supports Broadcast Receivers but with

Broadcast Receiver is taking too long to receive in onReceive() after airplane mode turned off/on

廉价感情. 提交于 2019-11-28 07:43:38
问题 I have created a simple Broadcast Receiver and it working absolutely fine except that if i turned on/off the Air Plane Mode, it is taking nearly 2 minutes to receive the broadcasted messages using onReceive method. Another thing is only this is causing a problem if we launch the application and then if i change Air plane Mode (on/off), Then it taking too long to receive the message. If there is Mode change before launching the application it didn't affect the time to receive the message in

BroadcastReceiver vs Service

主宰稳场 提交于 2019-11-28 07:39:14
Well, in android, what is the difference between doing something in broadcastReceiver and calling another service in broadcastReceiver ? I think they both run in background,right? Actually, what I what to do is: In certain time of everyday, download the user event(eg: 9:00 am eat breakfast) from database, and set up the AlarmManager to show notification about the event. Now I set up a alarm manager to do the above task. And I am puzzled should I directly accomplish this in BroadcastReceiver or call service in BroadcastReceiver to accomplish this. Thank You. You should do as LITTLE processing

How do I intercept button presses on the headset in Android?

帅比萌擦擦* 提交于 2019-11-28 06:59:34
I studied the ACTION_MEDIA_BUTTON intent and Im trying to use it and intercept the button presses and present them on screen using a toast. I registered the receiver to intercept two intents: ACTION_HEADSET_PLUG - plugging the headset ACTION_MEDIA_BUTTON - receiving the button presses This is done in my main activity: IntentFilter mediaFilter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON); mediaFilter.setPriority(10000); registerReceiver(_receiver, new IntentFilter(Intent.ACTION_HEADSET_PLUG)); registerReceiver(_receiver, mediaFilter); This is the part of the receiver that handles the button

Android: Wake & unlock phone

被刻印的时光 ゝ 提交于 2019-11-28 06:36:50
I am trying to figure out how to wake and unlock the phone with a service. I have been referring to this post but, I can't figure out why it isn't working. This is the code that I have so far: public class WakephoneActivity extends Activity { BroadcastReceiver mReceiver; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // Log.v(TAG, "Screen OFF onReceive()"); screenOFFHandler.sendEmptyMessageDelayed(0, 2000); } };

Accessing R from a BroadcastReceiver

老子叫甜甜 提交于 2019-11-28 06:30:42
问题 I want to change a TextView in the onReceive method of my BroadcastReceiver, but I can't access it with findViewById because it's not an activity. I don't want to create a private class for the BroadcastReceiver in my activity. How can I get access? 回答1: Define an interface and use a callback to let the activity know that a broadcast event has been received. public Interface BroadcastReceiverListener { void onReceive(int arg1, String arg2); ..<----add arguments you want to pass back } In your

Correct pattern to acquire a WakeLock in a BroadcastReceiver and release it in a Service

会有一股神秘感。 提交于 2019-11-28 06:25:22
Even after a lot of research I am still not completely sure if the way how I implement a WakeLock for a Service started by a BroadcastReceiver is correct - even though it seems to work fine. The broadcast receiver gets intents sent to it from an alarm, so to start with, from the API docs of AlarmManager : If your alarm receiver called Context.startService(), it is possible that the phone will sleep before the requested service is launched. To prevent this, your BroadcastReceiver and Service will need to implement a separate wake lock policy to ensure that the phone continues running until the

Service and a BroadCastReceiver

点点圈 提交于 2019-11-28 06:05:14
I have seen several examples of how to implement a BroadCastReceiver, but how should I implement a Service that has to react to some pending Intent (for example incoming phone call)... Actually I was wondering about the same "problem" but in an Activity.. You obviously have a class which extends a Service or an Activity) so it cannot also extend BroadCastReceiver... It looks like we cannot make "platform-aware" services and/or Activties? To register an activity to receive a certain intent you need to: // Flag if receiver is registered private boolean mReceiversRegistered = false; // I think

Android launch an activity from a broadcast receiver

拥有回忆 提交于 2019-11-28 05:57:31
问题 I know it may not be best practice but this is what i want to do. When my broadcast receiver is called - start a new activity which has is not fullscreen and has a transparent background - which opens on top of your current activity / desktop wallpaper. The code I have so far is as follows: I create + call a new activity with : Intent testActivityIntent = new Intent(context, com.andy.tabletsms.work.SMSPopup.class); testActivityIntent.putExtra("com.andy.tabletsms.message", main.msgs.get(i));

Android BroadcastReceiver won't work

[亡魂溺海] 提交于 2019-11-28 05:42:47
问题 I have a really simple problem which is driving me nuts. I am creating a BroadcastReceiver, declaring it on the manifest but it just wont run. I'm trying to make it trigger on device boot. Here's the code: package com.vullnetdyla.bcreceiver; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class Receiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.d(