My receiver is not showing notification - why? [duplicate] - java

This question already has answers here:
Android notification is not showing
(14 answers)
Closed 4 years ago.
//I had given intent in oncreate
Intent alarmIntent = new Intent(getContext(), ServiceReceiver.class);
pendingIntent = PendingIntent.getBroadcast(getContext(),
0, alarmIntent, 0);
// here i am setting alarm
public void setALARM(String time, String strDate){
AlarmManager manager = (AlarmManager) getContext()
.getSystemService(Context.ALARM_SERVICE);
String strHour=formateDateFromstring("HH:mm","HH",time);
String strMin=formateDateFromstring("HH:mm","mm",time);
String strdate=formateDateFromstring("yyyy-MM-dd","dd",strDate);
String strMonth=formateDateFromstring("yyyy-MM-dd","MM",strDate);
String strYear=formateDateFromstring("yyyy-MM-dd","yyyy",strDate);
int hour=Integer.parseInt(strHour);
int min=Integer.parseInt(strMin);
int date=Integer.parseInt(strdate);
int month=Integer.parseInt(strMonth)-1;
int year=Integer.parseInt(strYear);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH,date); //1-31
cal.set(Calendar.MONTH,month); //first month is 0!!! January is zero!!!
cal.set(Calendar.YEAR,year);//year...
cal.set(Calendar.HOUR_OF_DAY,hour); //HOUR
cal.set(Calendar.MINUTE,min);//MIN
cal.set(Calendar.SECOND,0);
manager.setExact(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
pendingIntent);
}
//Here is my receiver class
public class ServiceReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.logob_icon_prestigesalon)
.setContentTitle("ABC")
.setContentText("time to go")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
Toast.makeText(context,"service",Toast.LENGTH_LONG).show();
NotificationManager notificationmanager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationmanager.notify(0, builder.build());
}
}
//I mentioned receiver class in manifest
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver android:name=".ServiceReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<!-- Will not be called unless the application explicitly enables it -->
<receiver android:name=".DeviceBootReceiver"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
I want to set an alarm for the exact time.I checked the code in debug mode whether the debug is coming inside the onReceive if the given time comes.The debug is coming whe the given time is reached.The issue is notification is not visible.

Not sure if it is your specific problem, but NotificationCompat.Builder(Context context) is deprecated in API level 26.1.0. You should use NotificationCompat.Builder(Context, String) instead. All posted Notifications must specify a NotificationChannel Id for 26+ devices as you can check in Notification and Notification.Builder documentation

Try something like this,Have not tested.
String channelID = "Notification_Channel_ID";
String channelDesr = "Notification_channel_description";
buildNotificationChannel(channelID,channelDesr);
public void buildNotificationChannel(String channelID, String description) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager manager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
if (manager.getNotificationChannel(channelID) == null) {
NotificationChannel channel = new NotificationChannel(channelID, description,
NotificationManager.IMPORTANCE_LOW);
channel.setDescription(description);
manager.createNotificationChannel(channel);
}
}
}
NotificationCompat.Builder builder = new
NotificationCompat.Builder(context,channelID)
.setSmallIcon(R.drawable.logob_icon_prestigesalon)
.setContentTitle("ABC")
.setContentText("time to go")
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
Toast.makeText(context,"service",Toast.LENGTH_LONG).show();
NotificationManager notificationmanager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationmanager.notify(0, builder.build());

Related

Android Repeated Notifications not working When App is Closed

I want to send notification everyday on a particular time. The code is working when the app is opened. But when it closed and remove, the notifications are not showing. I have used broadcast receiver and service to this. The code is given below. Can anyone help to clear this issue.
Manifest File
<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="true" />
<service
android:name=".MyService"
android:enabled="true"
android:exported="true" />
MyReceiver.java
public class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
intent = new Intent(context, MyService.class);
context.startService(intent);
}}
MyService.java
public class MyService extends Service {
#Nullable
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
createNotification();
return Service.START_STICKY;
}
private static final String NOTIFICATION_CHANNEL_ID = "Channel01";
private void createNotification() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String name = preferences.getString("name", "User");
name = name.split(" ")[0];
String namee = "Remainder";
String description = "Remainder to update Wallet";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, namee, importance);
notificationChannel.setDescription(description);
Intent notifyIntent = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 1, notifyIntent, 0);
Notification notification = new Notification.Builder(getApplicationContext())
.setContentTitle("Remainder")
.setContentText("Hey " + name + ", Let's update your wallet")
.setSmallIcon(R.drawable.wallet)
.setChannelId(NOTIFICATION_CHANNEL_ID)
.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.wallet_new))
.setContentIntent(pendingIntent)
.build();
NotificationManager notificationManager = (NotificationManager)getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(notificationChannel);
// Issue the notification.
notificationManager.notify(1 , notification);
}
}}
Activity.java
Intent notifyIntent = new Intent(getApplicationContext(), MyReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1, notifyIntent, 0);
alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, timeMilli, timeInterval, pendingIntent);
You shouldn't use any part of application to do that. Services, JobScheduler, or Work Manager sooner or later will be killed by the system to prevent battery drain.
In my opinion the best way to send repeated notifications is to use firebase cloud messaging triggered with external cron job (e.g. php on firebase functions).
Also make sure to deliver the notification to the system tray not to the application. To do that use FCM DataMessages. Data messages are delivered to system tray and are always display - even if service is not running.

Unique Notifications at Unique Times with broadcastReceiver

i am currently devoloping small app and i struggle about sending notifications.
My Goal: I have different tasks and they need to send unique notifications at unique time to user even
while app is closed.
What I did?: I did create different broadCastReceiver's to make them work in harmony with
alarmManager' s but even i changed the request code , flag or channel code, i do get notifications at
same time if user enables notifications for more than one task, but alarmManagers for notifications
are not supposed to work after same time.
'receiver' part of AndroidManifest.xml
<receiver
android:name=".BroadcastReceiver"
android:exported="true">
<intent-filter>
<action
android:name="pendingIntent">
</action>
</intent-filter>
</receiver>
<receiver
android:name=".BroadcastReceiver2"
android:exported="true">
<intent-filter>
<action
android:name="pendingIntent2">
</action>
</intent-filter>
</receiver>
first and second broadCastReceiver
public class BroadcastReceiver extends android.content.BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
{
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "100")
.setSmallIcon(R.drawable.logologo)
.setContentTitle("Title")
.setContentText("Text")
.setPriority(NotificationCompat.PRIORITY_HIGH);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(100, builder.build());
}
}
}
public class BroadcastReceiver2 extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
NotificationCompat.Builder builder = new NotificationCompat.Builder(context,"102")
.setSmallIcon(R.drawable.logologo)
.setContentTitle("Title")
.setContentText("Text")
.setPriority(NotificationCompat.PRIORITY_HIGH);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(102, builder.build());
}
}
First and second Channel
public void createChannel1()
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
CharSequence name = "channel1";
String description = "channel1 description";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel1 = new NotificationChannel("100", name, importance);
channel1.setDescription(description);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel1);
}
}
public void createChannel2()
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
CharSequence name = "channel2";
String description = "channel2 description";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel2 = new NotificationChannel("102", name,importance);
channel2.setDescription(description);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel2);
}
}
Activity that needed to send Notification from first broadCastReceiver on Channel1 and
Activity that needed to send Notification from second broadCastReceiver on Channel2
button30.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Intent intent = new Intent(SmokeActivity.this, BroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(SmokeActivity.this, 100, intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
// Set the alarm to start at 8:30 a.m.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 8);
calendar.set(Calendar.MINUTE, 30);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
1000 * 60, pendingIntent);
}
});
button29.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Toast.makeText(WaterActivity.this, "Notifications Set", Toast.LENGTH_SHORT).show();
Intent intent2 = new Intent(WaterActivity.this, BroadcastReceiver2.class);
PendingIntent pendingIntent2 = PendingIntent.getBroadcast(WaterActivity.this,0,intent2,0);
AlarmManager alarmManager2 = (AlarmManager)getSystemService(ALARM_SERVICE);
// Set the alarm to start at 8:30 a.m.
Calendar calendar2 = Calendar.getInstance();
calendar2.setTimeInMillis(System.currentTimeMillis());
calendar2.set(Calendar.HOUR_OF_DAY, 8);
calendar2.set(Calendar.MINUTE, 30);
alarmManager2.setRepeating(AlarmManager.RTC_WAKEUP, calendar2.getTimeInMillis(),
1000*45, pendingIntent2);
}
});
For anyone suffering from same problem, the thing is android system does not allow us to send notification after first 10 minute when you create notification.

Notification not showing up when I close the app

So I made some code that makes the app show up at the time specified. It works well enough when the app is open on the screen, but when it is closed, it doesn't work at all. I need help making it show up.
Code for MainActivity.java:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initChannels(this);
alarmMgr = (AlarmManager)this.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this, MyReceiver.class);
alarmIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
// Set the alarm to start at 8:30 a.m.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 9);
calendar.set(Calendar.MINUTE, 00);
// setRepeating() lets you specify a precise custom interval--in this case,
// 20 minutes.
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, alarmIntent);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
Code for MyReceiver.java which extends BroadcastReceiver:
public MyReceiver() {
}
#Override
public void onReceive(Context context,Intent intent) {
Intent intent1 = new Intent(context, MyNewIntentService.class);
context.startService(intent1);
}
Code for MyNewIntentService which extends IntentService:
private static final int notificationId = 4242;
public MyNewIntentService() {
super("MyNewIntentService");
}
#Override
protected void onHandleIntent(Intent intent) {
//NOTIFICATION CREATION
// Create an explicit intent for an Activity in your app
Intent notifyIntent = new Intent(this, MainActivity.class);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, "default")
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle("This is the title")
.setContentText("This is the body of the notification.")
.setVisibility(VISIBILITY_PUBLIC)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
// Set the intent that will fire when the user taps the notification
.setContentIntent(pendingIntent)
.setAutoCancel(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
// notificationId is a unique int for each notification that you must define
notificationManager.notify(notificationId, mBuilder.build());
}
And I added this in the AndroidManifest.xml:
<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="false" >
</receiver>
<service
android:name=".MyNewIntentService"
android:exported="false" >
</service>
I know there's a lot of text in this question and I apologize for that, but I think that'll make it easier for you to help me or see what the problem is.
try this
firebase notification are two types:
data message: when your app background/foreground/killed your push notification is worked
display message: when your app foreground push notification works
Handle push notification these stages background/foreground/killed
it depends your json response make sure your json response like this:
{
"to": "registration_ids",
"data": {
"key": "value",
"key": "value",
"key": "value",
"key": "value"
}
}
this is my code when your app background/foreground/killed it works fine
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.e(TAG, "remoteMessage......" + remoteMessage.getData());
try {
Map<String, String> params = remoteMessage.getData();
JSONObject object = new JSONObject(params);
Log.e(TAG, object.toString());
body = object.getString("not_id");
dataa = object.getString("data");
title = object.getString("not_type");
type = object.getString("type");
Sender = object.getString("Sender");
SenderProfileUrl = object.getString("SenderProfileUrl");
wakeUpScreen();
addNotification(remoteMessage.getData());
}
/* when your phone is locked screen wakeup method*/
private void wakeUpScreen() {
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn();
Log.e("screen on......", "" + isScreenOn);
if (isScreenOn == false) {
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "MyLock");
wl.acquire(10000);
PowerManager.WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyCpuLock");
wl_cpu.acquire(10000);
}
}
/*Add notification method use for add icon and title*/
private void addNotification(Map<String, String> data) {
int icon = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?R.drawable.logo_app: R.drawable.logo_app;
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(icon)
//.setSmallIcon(R.drawable.logout_icon)
.setContentTitle(data.get("title") + "")
.setChannelId("channel-01")
.setAutoCancel(true)
.setSound(uri)
.setContentText(data.get("body") + "");
Notification notification = new Notification();
Log.e(TAG, "titlee" + data.get("title"));
// Cancel the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
if (sound)
notification.defaults |= Notification.DEFAULT_SOUND;
if (vibration)
notification.defaults |= Notification.DEFAULT_VIBRATE;
builder.setDefaults(notification.defaults);
}
}
when i click notification bar goto the particular screen using type like this:
/*notification send with type calling */
if (data.get("not_type").equals("calling")) {
if (data.get("type").equals("name")) {
Log.e(TAG, "ttt--" + type);
Intent notificationIntent = new Intent(this, CallingActivity.class);
notificationIntent.putExtra("notification_room_id", body);
notificationIntent.putExtra("data", dataa);
notificationIntent.putExtra("calling", "calling");
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);
builder.setSound(uri);
builder.setAutoCancel(true);
// Add as notification
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "Hello";// The user-visible name of the channel.
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel("channel-01", name, importance);
manager.createNotificationChannel(mChannel);
}
manager.notify((int) ((new Date().getTime() / 1000L) % Integer.MAX_VALUE), builder.build());
}
this is my manifest add notification class and token class
<service android:name=".notification.NotificationService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name=".notification.TokenService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service
android:name=".notification.NLService"
android:label="#string/app_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
i hope it helps you

How to send notification on boot completed?

I've got the following class called AlarmNotificationReceiver.
The idea is to send a notification when the device is turned out. Something seems to be wrong since this isn't happening. Any ideas why?
public class AlarmNotificationReceiver extends BroadcastReceiver{
public void onReceive(Context context, Intent intent) {
if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle("HEY I WAS INITIALIZED!");
builder.setContentText("Good luck");
builder.setSmallIcon(R.drawable.alert_icon);
builder.setAutoCancel(true);
builder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 });
builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.notif_red));
//notification manager
Notification notification = builder.build();
NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
manager.notify(1234, notification);
}
}
}
I also added the following lines to the manifest:
<receiver android:name=".AlarmNotificationReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
You are missing creation of notification channel. You can create notification as follows:
public class AlarmNotificationReceiver extends BroadcastReceiver{
public void onReceive(Context context, Intent intent) {
if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){
...
createNotificationChannel(context);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context,1000);
...
}
}
private void createNotificationChannel(final Context context) {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "ChannelName";
String description = "Channel description";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(1000, name, importance);
channel.setDescription(description);
NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}
}

Android notification programmed

I have build a simple app that show a notification when i click on a button. How can show a programmed notify?
The code that i call is:
Notification.Builder builder = new Notification.Builder(this)
.setTicker("Notifica")
.setSmallIcon(android.R.drawable.stat_notify_chat)
.setContentTitle("Notifica")
.setContentText("Hai una notifica!")
.setAutoCancel(true)
.setContentIntent(PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0));
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify("interstitial_tag", 1, builder.build());
You can use AlarmManager in bundle with BroadcastReceiver.
At first you must create pending intent and register it with AlarmManager.set somewhere.
And then create your broadcast receiver and receive that intent.
Update: here is the code I have promised.
At first you need to create broadcast receiver.
public class NotifyHandlerReceiver extends BroadcastReceiver {
public static final String ACTION = "me.pepyakin.defferednotify.action.NOTIFY";
public void onReceive(Context context, Intent intent) {
if (ACTION.equals(intent.getAction())) {
Notification.Builder builder = new Notification.Builder(context)
.setTicker("Notifica")
.setSmallIcon(android.R.drawable.stat_notify_chat)
.setContentTitle("Notifica")
.setContentText("Hai una notifica!")
.setAutoCancel(true)
.setContentIntent(PendingIntent.getActivity(context, 0,
new Intent(context, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0));
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify("interstitial_tag", 1, builder.build());
}
}
}
This is your broadcast receiver that can handle notification requests. For it can work, you must register it in your AndroidManifest.xml. If you don't do it, Android won't be able to handle your notification request.
Just add <receiver/> declaration into your <application/> tag.
<receiver android:name=".NotifyHandlerReceiver">
<intent-filter>
<action android:name="me.pepyakin.defferednotify.action.NOTIFY" />
</intent-filter>
</receiver>
Take a note, that action name be exactly as defined in NotifyHandlerReceiver.ACTION.
Then you can use this code
public static final int REQUEST_CODE_NOTIFY = 1;
public void scheduleNotification(long delayTimeMs) {
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
long currentTimeMs = SystemClock.elapsedRealtime();
PendingIntent pendingNotifyIntent = PendingIntent.getBroadcast(
this,
REQUEST_CODE_NOTIFY,
new Intent(NotifyHandlerReceiver.ACTION),
PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, currentTimeMs + delayTimeMs, pendingNotifyIntent);
}
from your activity to start a notification delayed on delayTimeMs amount of milliseconds.

Categories

Resources