在3.0之後,針對status bar notification,google已經不建議使用
應該要改用 Notification.Builder 來取代。
詳細使用參考網頁
程式範例如下:
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder mNotificationBuilder = new Notification.Builder(this);
Intent anotherIntent = new Intent(context, AnotherActivity.class);
mNotificationBuilder.setSmallIcon(R.drawable.icon)
.setAutoCancel(false)
.setContentTitle("Title")
.setContentText("Notification Message Content")
.setContentIntent(PendingIntent.getActivity(context, 0, anotherIntent, 0));
mNotificationManager.notify(R.drawable.icon, mNotificationBuilder.getNotification());
執行結果如下
Notification notification = new Notification(icon, tickerText, when);這樣的用法,
應該要改用 Notification.Builder 來取代。
詳細使用參考網頁
程式範例如下:
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder mNotificationBuilder = new Notification.Builder(this);
Intent anotherIntent = new Intent(context, AnotherActivity.class);
mNotificationBuilder.setSmallIcon(R.drawable.icon)
.setAutoCancel(false)
.setContentTitle("Title")
.setContentText("Notification Message Content")
.setContentIntent(PendingIntent.getActivity(context, 0, anotherIntent, 0));
mNotificationManager.notify(R.drawable.icon, mNotificationBuilder.getNotification());
執行結果如下
沒有留言:
張貼留言