broadcastreceiver

Dynamic Registration vs Static Registration of BroadcastReceiver

妖精的绣舞 提交于 2019-11-30 17:30:28
All of us known we register BroadcastReceiver in two types 1)Static Registration 2)Dynamic Registration But my doubt is when we need to use Static and when we need to use Dynamic ? Jitesh Upadhyay As we know there are two ways to register a BroadcastReceiver ; one is static and the other dynamic . Static: Use tag in your Manifest file. (AndroidManifest.xml) Not all events can be registered statically. Some events require permissions. Dynamic: Use Context.registerReceiver() to dynamically register an instance. Note: Unregister when pausing. When we are doing dynamic registration (i.e. at run

Android keep BroadcastReceiver in background

夙愿已清 提交于 2019-11-30 17:18:44
问题 I created a BroadcastReceiver and it runs only when my app shown in recent apps menu. If I remove my app from the recent apps the BroadcastReceiver will stop working. How can I keep the BroadcastReceiver in background? I register the BroadcastReceiver from my main activity (in OnCreate()). IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); registerReceiver(receiver, intentFilter); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive

Boot/ScreenOn Broadcast Receiver not working

冷暖自知 提交于 2019-11-30 17:18:15
问题 I have a blank HelloWorld Application: package tutorials.TestReceivers; import android.app.Activity; import android.os.Bundle; public class TestReceiversActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } With this BootReceiver.Java: package tutorials.TestReceivers; import android.content.BroadcastReceiver; public class BootReceiver

Register a Local BroadcastReceiver in AndroidManifest.xml?

混江龙づ霸主 提交于 2019-11-30 16:54:23
Is there anyway to register a BroadcastReceiver in AndroidManifest.xml and receives broadcast that is send by a LocalBroadcastManager? Currently I must call registerReceiver(BroadcastReceiver receiver, IntentFilter filter) to register a Receiver, declare in AndroidManifest.xml won't work. But this means I must know exactly the receiver's package name and class name, not just the intent filter. Is it possible to declare the receiver in the manifest file? following is my current code. AndroidManifest.xml: ... <receiver android:name="com.example.test.MessageReceiver" android:enabled="true" >

How to Cancel AlarmManager on a Scheduled time

随声附和 提交于 2019-11-30 16:45:05
How can I cancel one AlarmManager on a scheduled time, which was already started. I am starting one AlarmManager like this. I want to cancel it after 5 hours. How can I do this? AlarmManager service = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, MyStartServiceReceiver.class); PendingIntent pending = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, 30); service.setInexactRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), REPEAT_TIME, pending); set

Reboot receiver is not working in xiaomi phones

白昼怎懂夜的黑 提交于 2019-11-30 16:38:18
问题 Hi We are working on an android application where we are using reboot receiver in which I am starting few services where I am performaning some network operation. I figured it out that in some android devices like xiaomi etc reboot receiver is not working. Earlier I got to know that In HTC devices also it does not work so I added one more intent filter to it <action android:name="android.intent.action.QUICKBOOT_POWERON" /> then it started working fine. Now other phones like xiaomi it's still

Android: detect when app is installed

让人想犯罪 __ 提交于 2019-11-30 16:30:01
I am trying to download an Android app from a server using the DownloadManager class, install it and then detect when the installation is completed. I am using two receivers: one to detect the download process and the other to detect the install process. The first receiver works properly, but the second doesn't. What I am doing wrong? DownloadManager dm = (DownloadManager) DownloadApplicationActivity.this.getSystemService(Context.DOWNLOAD_SERVICE); DownloadManager.Request req = new DownloadManager.Request(Uri.parse(MY_LINK)); req.setTitle(MY_TITLE) .setDescription("Downloading ....") //

getActiveNotifications always null when using NotificationListenerService

泪湿孤枕 提交于 2019-11-30 16:20:56
I followed this Sample Code of kpBird and this Developer Guide I can : Call intent to this service. Can catch Broadcast from Notification. So I got the error getActiveNotifications always null . I don't know why, People who know, please help me, Thanks, p/s : Here is source code and error I get. Error : 04-28 08:46:11.625: E/AndroidRuntime(7651): FATAL EXCEPTION: main 04-28 08:46:11.625: E/AndroidRuntime(7651): java.lang.RuntimeException: Error receiving broadcast Intent { act=app.trekband.NotificationListener flg=0x10 (has extras) } in utils.NotificationListener$NLServiceReceiver@42680780 04

service automatically stops after several minutes

六月ゝ 毕业季﹏ 提交于 2019-11-30 16:00:45
问题 I'm creating a service which should work when the activity is in background as well as when the whole application is destroyed. I'm calling location coordinates in the service at every 1 minute interval. However, when I try to do so, the service shuts down automatically just after 12-15 minutes. I want the service to work endlessly until and unless it is destroyed by the completion of activity on user interaction. My service class is as follows: public class SensorService extends Service {

Broadcast data to multiple widgets in Flutter

别等时光非礼了梦想. 提交于 2019-11-30 15:40:52
Is there a way to broadcast data from one widget to other widgets? Similar to a BroadcastReceiver on Android or NSNotificationCenter on iOS. Specifically, I'm trying to detect when a Navigator pops or pushes a new view. I added navigatorObservers to MaterialApp. And when a widget comes back to the foreground, I want to be able to notify it by broadcasting changes from didPush and didPop with the actual route that's in the current foreground Navigator.push returns a Future that will complete when Navigator.pop is called (and this can optionally be used to pass data back to the widget that