Android device reboot/restart sends notifications immediately regardless of time - android

In my AndroidManifest.xml, I added an intent-filter to my receiver so that my notifications are still being sent even if the user reboots/restarts their device.
<receiver
android:name="NotificationAlarmReceiver"
android:directBootAware="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
This works, but my problem is once the device has been rebooted/restarted, it immediately sends the notification regardless of the hour and minute that were set for the notifications.
I don't want my notifications to be immediately sent. I want them to be activated again since a reboot/restart deletes all notifications that were setup on the user's device and only send notifications at the hour and minute that they were set to. How do I do that?

Related

Detect system reboot from inside a service

Is it possible to detect when a service is stopped or destroyed by one of its own methods? e.g.
onDestroy() (not currently working)
What I need is to detect, from inside the service, whenever the device is rebooted or turned off.
You could create a BroadcastReceiver to listen for the ACTION_SHUTDOWN and QUICKBOOT_POWEROFF intents:
<receiver android:name=".PowerOffReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
<action android:name="android.intent.action.QUICKBOOT_POWEROFF" />
</intent-filter>
</receiver>
Conversely you can listen for the BOOT_COMPLETED intent for when the phone is back on:
<receiver android:name=".PowerOnReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
Keep in mind the latter requires the device to be unlocked by the user first. In newer API, you can listen for LOCKED_BOOT_COMPLETED which will allow you to start your service or do whatever you need before the device is unlocked.

Broadcast receiver invoking on every reboot

I have registered a broadcast Receiver with which should wake the application up on every reboot,
receiver android:name=".Receiver.NewLocationReceiver"
<intent-filter>
<category android:name="android.intent.category.HOME" />
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="YouWillNeverKillMe" >
</action>
</intent-filter>
</receiver>
Still the BOOT_COMPLETE filter if failing to do its job, Unable to tackle a particular scenario. Is there anything I need to add so that I can completely avoid this situation.
Popular pitfalls:
BOOT_COMPLETED is delivered to all relevant (registered) broadcast receivers only upon unlocking the device.
It is delivered in some order, so you may be last in that list and will take some time.
Make sure you have the presmission <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

how to enable Notification Listener without restart the device

I just enabled Notification Access permission to my app. But the Notification Listener starts Only I restart the device.How can I enable the service once my app gets installed?
You have to register a receiver in your AndroidManifest.xml.
Like below (This is an example of the GCM listener for Google Cloud Messaging)
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
</intent-filter>
</receiver>
Let me know if you need more info. But I assume you know how this works since you seem to have implemented the
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
Can you share you AndroidManifest.xml?

Why my phone does not get alert from receiver when my app is not running on background?

I have an app and I want to get notifications. It works fine when my phone is running background. But when I clear memory or restart my phone it is not getting notifications.
My Receiver extends BroadcastReceiver class. And I use this on manifest:
<receiver android:name=".Main$MyReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.xx.UPDATE_STATUS" />
</intent-filter>
</receiver>
I want to get notifications when my app is running on foreground, background , I mean every time is it possible?

Listening for package change events of certain package

I have a pro key application package for my application, and I would like to set up a BroadcastReceiver to receive intents when the pro key package is added or updated. Here's my code:
<receiver android:name=".Receiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_CHANGED" />
<data android:scheme="package" android:path="com.test.key"/>
</intent-filter>
</receiver>
The code starts up the receiver on every app I install or update the com.test.key app, but it fires for every other apps as well. How can I listen for package updates for com.test.key only?
I know how to do it in the Receiver.java (intent.getData().getSchemeSpecificPart()). I'm looking for a way to do the filtering in the Android Manifest, so the broadcast doesn't get fired every time user installs an app.

Categories

Resources