broadcastreceiver

Android 8.0 Oreo AlarmManager with broadcast receiver and implicit broadcast ban

[亡魂溺海] 提交于 2019-11-27 22:18:50
I have critical reminders that are set via the Alarm Manager (It should function the same way as an alarm clock application). Previously I had the following in my Android Manifest: <receiver android:name="com.example.app.AlarmReceiver" > <intent-filter> <action android:name="${packageName}.alarm.action.trigger"/> </intent-filter> </receiver> The broadcast receiver: public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive( final Context context, final Intent intent) { // WAKE LOCK // BUILD NOTIFICATION etc... } } How the alarm is set: final PendingIntent operation

How to detect headphone plug event in “offline” mode [closed]

南楼画角 提交于 2019-11-27 21:41:41
I know how to detect headphone plug in event if my application is running. You have to register broadcast receiver for ACTION_HEADSET_PLUG. But you can't capture this action using Manifest declaration for broadcast receiver. Therefore the only option to capture headphone plug in event is background service. But it drains battery and so on. I checked out some music players and figured out that they capture that event without any additional services. How do they do that? Any ideas? Phil I've had an app in the store for three years that monitors both the wired headset and bluetooth state and

Pass data from BroadcastReceiver class to a Android Activity

六月ゝ 毕业季﹏ 提交于 2019-11-27 21:38:15
I'm developing an Android application and it has a functionality that while the application is running if I receive an new SMS message the content of that message need to be read using TextToSpeech. I know how to read a text using TextToSpeech. I have written two classes on my application. one is MainActivity extends from Activity and the other one is SmsReceiver extends from BroadcastReceiver. When a Sms is received while the MainActivity is running I want get the content of the sms message using SmsReceiver and pass it to MainActivity and then read it inside MainActivity using TextToSpeech.

BroadcastReceiver for Screen On/Off not working

拥有回忆 提交于 2019-11-27 21:37:18
I am trying to use BroadcastReceiver but it is not working, please help me to solve this problem. MyReceiver.java package com.example.broadcast_receiver; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; public class MyReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub Log.i("[BroadcastReceiver]", "MyReceiver"); if(intent.getAction().equals(Intent.ACTION_SCREEN_ON)){ Log.i("[BroadcastReceiver]", "Screen ON"); } else if(intent

Shared preferences inside broadcastreceiver

青春壹個敷衍的年華 提交于 2019-11-27 21:00:24
In my app,i want to use Shared Preferences inside a broadcast receiver...But i cant access the getPreferences() method inside... SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE); I cant call with the context object...any other method??? You can use Context from onReceive(Context arg0, Intent arg1) of BroadReceiver. @Override public void onReceive(Context arg0, Intent arg1) { SharedPreferences prefs = arg0.getSharedPreferences("myPrefs", Context.MODE_PRIVATE); } 来源: https://stackoverflow.com/questions/9075030/shared-preferences-inside-broadcastreceiver

Passing Data from Broadcast Receiver to another Activity

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 20:55:41
Hi I've been having an issue with Broadcast Receivers and passing information to another activity. I'm trying to create an application that will capture incoming SMS messages, look for a website in the text, then pop up an Alert Dialog box asking if the user wants to go to the website. public class TextReceiver extends BroadcastReceiver{ public void onReceive(Context context, Intent intent) { // .. other code that // sets received SMS into message Toast toast = Toast.makeText(context, "Received Text: " + message.getMessageBody(), Toast.LENGTH_LONG); toast.show(); } So that code works fine,

Main difference between Manifest and Programmatic registering of BroadcastReceiver

。_饼干妹妹 提交于 2019-11-27 20:36:05
I am trying to understand the main differences between registering a BroadcastReceiver in the Manifest and registering it programmatically... My understanding is basically as follows (would appreciate someone correcting my points if I am missing something). Registered in Manifest: The OS will magically find and instantiate your class if needed, calling the onReceive() method, regardless what the running state of your application was Your receive will only get called once per broadcast (i.e. You can consider that registering in the manifest is like registering your 'class' for receiving the

AlarmManager and BroadcastReceiver instead of Service - is that bad ? (Timeout)

笑着哭i 提交于 2019-11-27 19:51:27
BACKGROUND INFO: I need to update some data from the web, about every hour or so, even when my app is closed. The update of the data itself takes about 40 seconds to 1 minute. It is then saved as a Serializable to a file. This file is read when my app starts. THIS IS THE APPROACH I TOOK FOR THE MOMENT (not using a Service) use the AlarmManager and BroadcastReceiver like this : private void set_REFRESH_DATA_Alarm(){ mContext = Main.this; alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); broadcast_intent = new Intent(mContext, RepeatingAlarmReceiver_REFRESH_DATA.class);

Calling a Activity method from BroadcastReceiver in Android

匆匆过客 提交于 2019-11-27 19:41:29
Here I am creating an online application that depends only on Internet. So whenever there is a network error it must notify user. For that, I have created a BroadcastReciver that receives call when network connection gets lost(Internet). All this works perfectly. Now what I need is that I have to call a method of Activity from this Broadcast Receiver, where I have created an Alert Dialogue. I have read many answers on stack-overflow.com that I can declare that method static and call by using only Activity name, e.g MyActivityName.myMethod() But I can't declare my method static, because I am

Android broadcast receiver doesn't receive ACTION_SCREEN_ON

♀尐吖头ヾ 提交于 2019-11-27 19:02:41
问题 I tried to register the receiver in my service with the following code: IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); ScreenReceiver SR = new ScreenReceiver(); registerReceiver(SR, filter); and this is my broadcast receiver: public class ScreenReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { System.out.println("RECEIVED"); } } I have even declared it in the manifest but without any filters: <receiver android:name="