①ステータスバーに表示する
②ステータスバーに通知が蓄積される
これは、標準で用意されているNotificationManagerで簡単に、任意のメッセージやアイコンを持った通知を発行できます。
まずは、通知内容をNotificationに設定します。
- // Context context;
- // String message, item_title, item_message;
- Notification n = new Notification();
- n.icon = R.drawable.ic_launcher;// アイコン(drawable指定)ここではアプリのアイコン
- n.tickerText = message;// ステータスバーに表示する文字列(CharSequence指定)
- n.when = System.currentTimeMillis();
- // 通知をタップしたときに発行するインテント
- Intent i = new Intent(context, RpNotifyActivity.class);
- n.setLatestEventInfo(context, item_title, item_message, PendingIntent.getActivity(context, 0, i, 0));
- NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
- manager.notify(1,n);