Java – notifications builder in Android 2.3

Android is new here:)

If the target version of the application is > I have a notification builder, there is no problem. 4 however, when I switch to 2.3, I receive an error on this line, which says "notificaiton. Builder cannot resolve to a certain type"

Notification notification = new Notification.Builder(this)
            .setSmallIcon(drawable_small)
            .setLargeIcon(drawable_big)
            .setWhen(System.currentTimeMillis()).setTicker(content_title)
            .setContentTitle(content_title).setContentInfo(content_info)
            .setContentText(content_text).setContentIntent(pIntent)
            .getNotification();

This problem is solved now! But now I have another error that it gives me every R (resource). I can choose to import R. if I import it, it will give me every resource error

setContentView(R.layout.activity_main);

resolvent:

Realize your notice like you

     Notification noti = new NotificationCompat.Builder(context)
                    .setSmallIcon(icon_small)
                    .setTicker(message)
                    .setLargeIcon(largeIcon)
                    .setWhen(System.currentTimeMillis())
                    .setContentTitle(title)
                    .setContentText(message)
                    .setContentIntent(contentIntent)
                    //At most three action buttons can be added
                    .setAutoCancel(true).build();

And add the support library V4 to the project and import it

import android.support.v4.app.NotificationCompat;

Notificationcompat helper for backward compatible access to functions in notification introduced after API level 4

For more information, visit: http://developer.android.com/guide/topics/ui/notifiers/notifications.html

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>