我想用一个按钮来通知,但两者通知,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通知管理器
发布评论