Intent i = new Intent(getBaseContext(), MyReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(MainActivity.this, 100,i, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 5000, pi);
}
});
}
private void create()
{
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
String tag="mm";
Log.d(tag,"xyz");
NotificationChannel notificationChannel = new NotificationChannel("abc","abc",NotificationManager.IMPORTANCE_HIGH);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(notificationChannel);
}
//Receiver class
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationCompat.Builder notification = new NotificationCompat.Builder(context,"abc")
.setContentTitle("Title")
.setContentText("text")
.setPriority(NotificationManager.IMPORTANCE_HIGH)
.setSmallIcon(R.drawable.ic_launcher_background);
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context);
notificationManagerCompat.notify(1,notification.build());
}
}
Manifest file is updated also. I've called create function in onCreate. If anyone can help me. I've been stuck on this for a week