I found that I am using a deprecated method for noficitations (notification.setLatestEventInfo())
It says to use Notification.Builder.
When I try to create a new instance, it tells me:
Notification.Builder cannot be resolved to a type
To make this possible, Android N uses the existing NotificationCompat. Builder. setGroup() method. Users can expand each of the notifications, and perform actions such as reply and dismiss on each of the notifications, individually from the notification shade.
android.app.Notification.Builder. Builder class for Notification objects. Provides a convenient way to set the various fields of a Notification and generate content views using the platform's notification layout template.
NotificationCompat.Action. Structure to encapsulate a named action that can be shown as part of this notification. NotificationCompat.Action.Builder. Builder class for Action objects.
Notification.Builder API 11 or NotificationCompat.Builder API 1
This is a usage example.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With