通知生成器中的Andr​​oid 2.3 [英] Notifications Builder in android 2.3

查看:150
本文介绍了通知生成器中的Andr​​oid 2.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pretty在android的新位置:)

我有一个通知,其中建设者没有问题的工作,如果该应用程序的目标版本> 4.0
然而,当我切换到2.3我在这一行它说Notificaiton.Builder不能被解析为一个类型得到一个错误。

 的通知的通知=新Notification.Builder(本)
            .setSmallIcon(drawable_small)
            .setLargeIcon(drawable_big)
            .setWhen(System.currentTimeMillis的())。setTicker(content_title)
            .setContentTitle(content_title).setContentInfo(content_info)
            .setContentText(content_text).setContentIntent(pIntent)
            。得到通知();

此问题现在已经解决了!
但是我真的现在不得不另外一个
它给了我一个错误的每个R(资源),我可以选择导入R.
如果我导入它,它给我的错误上的每个资源。

 的setContentView(R.layout.activity_main);


解决方案

实施你的通知

 通知NotI位=新NotificationCompat.Builder(上下文)
                    .setSmallIcon(icon_small)
                    .setTicker(消息)
                    .setLargeIcon(largeIcon)
                    .setWhen(System.currentTimeMillis的())
                    .setContentTitle(职称)
                    .setContentText(消息)
                    .setContentIntent(co​​ntentIntent)
                    //最多三个动作按钮可以添加
                    .setAutoCancel(真).build();

和增加支持库V4 到你的项目,也导入

 进口android.support.v4.app.NotificationCompat;

NotificationCompat 帮手在通知 API级别4 向后兼容的方​​式即可。

有关更多信息,请访问: http://developer.android。 COM /引导/主题/ UI /通知者/ notifications.html

Pretty new in android here :)

I have a notification builder which works with no problem if the application target version is > 4.0 However when I switch to 2.3 I get an error on this line which says "Notificaiton.Builder cannot be resolved to a 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 now solved! However I`m having another one now It gives me an error on every R (resource) and I have the option to Import R. If I import it,its giving me errors on every resource.

setContentView(R.layout.activity_main);

解决方案

Implement your Notification like

     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 support library v4 into your project and also import

import android.support.v4.app.NotificationCompat;

NotificationCompat helper for accessing features in Notification introduced after API level 4 in a backwards compatible fashion.

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

这篇关于通知生成器中的Andr​​oid 2.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆