I'm trying to set a notification in my Android app that just says “It worked”, but I need my app to be compatible right down to API 1. I am really confused about how to do this though. There are old tutorials that are out of date, and there are new tutorials that do not support older API levels. In accordance with this question, https://stackoverflow.com/a/166269/2326323 should I use NotificationCompat.Builder . There is an example that I use, but I do not quite understand the code.
From this code:
Intent notificationIntent = new Intent(ctx, YourClass.class); PendingIntent contentIntent = PendingIntent.getActivity(ctx, YOUR_PI_REQ_CODE, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationManager nm = (NotificationManager) ctx .getSystemService(Context.NOTIFICATION_SERVICE); Resources res = ctx.getResources(); Notification.Builder builder = new Notification.Builder(ctx); builder.setContentIntent(contentIntent) .setSmallIcon(R.drawable.some_img) .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.some_big_img)) .setTicker(res.getString(R.string.your_ticker)) .setWhen(System.currentTimeMillis()) .setAutoCancel(true) .setContentTitle(res.getString(R.string.your_notif_title)) .setContentText(res.getString(R.string.your_notif_text)); Notification n = builder.build(); nm.notify(YOUR_NOTIF_ID, n);
I get red lines under: ctx , YOUR_PI_REQ_CODE and YOUR_NOTIF_ID
EGHDK source share