Edit: SOLVED! Ever wanted to set a notification from a specific date starting a certain point in time (when an activity is started or when a button is pressed?) Read more to
One Important thing to note:
When registering your broadcast receiver with an Intent-Filter
, you need to add the exported
attribute and set it to false. Like this:
<service
android:name=".utility.AlarmReceiver" android:exported="false">
<intent-filter>
<action android:name="NOTIFICATION_SERVICE" />
</intent-filter>
</service>
Else components of other apps will be able to invoke or interact with your service.
Full explanation from Google:
android:exported
Specifies whether or not components of other applications
can invoke the service or interact with it —
"true" if they can, and "false" if not.
When the value is "false", only components of the same application or
applications with the same user ID can start the service or bind to it.
The default value depends on whether the service contains intent filters.
The absence of any filters means that it can be invoked only by specifying
its exact class name. This implies that the service is intended only for
application-internal use (since others would not know the class name). So
in this case, the default value is "false". On the other hand, the presence
of at least one filter implies that the service is intended for external
use, so the default value is "true".
Don't forget to give the below manifest permissions
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
Your broadcast receiver registrations would be like this
<receiver android:name=".AlarmReceiver" >
<intent-filter>
<action android:name="NOTIFICATION_SERVICE" />
</intent-filter>
</receiver>