问题在Android通知管理器

编程入门 行业动态 更新时间:2024-10-27 12:27:33
本文介绍了问题在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通知管理器

本文发布于:2023-11-27 04:42:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636641.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:管理器   通知   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!