0

So, I'm developing an Android App and I need to send a notification of a certain event at a certain time.

However, for some reason the notification itself isn't showing up, despite the app not returning any errors or anything of the sort.

What could I possibly be doing wrong? This is my Receiver class.

The test print works properly so I don't think the connection to the receiver is the problem.

public class NotReceiver extends BroadcastReceiver{
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onReceive(Context context, Intent intent) {
    System.out.println("test");
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL)
            .setContentTitle("doge")
            .setContentText("456")
            .setSmallIcon(R.mipmap.ic_launcher)
            .build();

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, builder.build());
    }
}

This is my Alarm function

@RequiresApi(api = Build.VERSION_CODES.O)
public void sendNotif(View view) {

    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent myIntent;
    PendingIntent pendingIntent;

    myIntent = new Intent(EventsActivity.this, NotReceiver.class);
    pendingIntent = PendingIntent.getBroadcast(this, 0, myIntent, 0);

    am.set(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime()+100, pendingIntent); 
}
Ishaan Javali
  • 1,711
  • 3
  • 13
  • 23
Rui
  • 73
  • 2
  • 9
  • 2
    Possible duplicate of [Notification not showing in Oreo](https://stackoverflow.com/questions/43093260/notification-not-showing-in-oreo) – Floern Jul 17 '18 at 17:36
  • yep, it was the missing channel ID. – Rui Jul 17 '18 at 18:00

0 Answers0