问题在Android通知管理器 [英] Issue with Notification Manager on android

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

问题描述

我想用一个按钮来通知,但两者通知,setLatestEventInfo被触击Eclipse的。

I'm trying to notify using a button,but both Notification,setLatestEventInfo was stricken on Eclipse.

两个错误:

1,构造通知(INT,CharSequence中,长期)是德precated 通知通知=新的通知(android.R.drawable.stat_notify_more,大家好,System.currentTimeMillis的( ));

1.The constructor Notification(int, CharSequence, long) is deprecated Notification notify = new Notification(android.R.drawable.stat_notify_more, "Hello all", System.currentTimeMillis());

2,方法 setLatestEventInfo(背景下,为CharSequence,CharSequence中,的PendingIntent)的通知类型不适用于参数(背景下,为CharSequence ,CharSequence中,意图)notify.setLatestEventInfo(背景下,职称,详细的意图);

2.The method setLatestEventInfo(Context, CharSequence, CharSequence, PendingIntent) in the type Notification is not applicable for the arguments (Context, CharSequence, CharSequence, Intent) notify.setLatestEventInfo(context, title, details, intent);

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button b = (Button) findViewById(R.id.button1);
    b.setOnClickListener(new View.OnClickListener() {   
        @Override
        public void onClick(View v) {
            NotificationManager ns = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            Notification notify = new Notification(android.R.drawable.stat_notify_more, "Hello all", System.currentTimeMillis());
            Context context = MainActivity.this;
            CharSequence title ="you have be notified";
            CharSequence details = "Continue your work";
            Intent intent = new Intent(context,MainActivity.class);
            PendingIntent pending = PendingIntent.getActivity(context, 0, intent, 0);
            notify.setLatestEventInfo(context, title, details, intent);
            ns.notify(0,notify);


        }
    });
}

API级别:

       android:minSdkVersion="11"
       android:targetSdkVersion="17"

如何修复错误?

推荐答案

1。构造函数在API级别11 pcated德$ P $。所以你应该使用 Notification.Builder

为例如

Notification notification = new Notification.Builder(mContext)
     .setContentTitle("New mail from " + sender.toString())
     .setContentText(subject)
     .setSmallIcon(R.drawable.new_mail)
     .setLargeIcon(aBitmap)
     .build();

2。在code您传递的意图,而不是在setLatestEventInfo挂起

....
Intent intent = new Intent(context,MainActivity.class);
        PendingIntent pending = PendingIntent.getActivity(context, 0, intent, 0);
        notify.setLatestEventInfo(context, title, details, pending);
        ns.notify(0,notify);
....

这篇关于问题在Android通知管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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