ラベル Notification の投稿を表示しています。 すべての投稿を表示
ラベル Notification の投稿を表示しています。 すべての投稿を表示

2012年3月19日月曜日

Notificationのフラグによる動作の設定


Notificationクラスのflagフィールドに代入することで、下記設定が可能
フラグは OR で代入して、複数設定することも出来る。

Notification.FLAG_AUTO_CANCEL
 しばらくすると自動的に通知が消える。ポップアップでお知らせするために使える

Notification.FLAG_INSISTENT
 通知ウィンドウを開くか、キャンセルされるまで、音が鳴り続ける。かなりうざそう

Notification.FLAG_ONGOING_EVENT
 通常の通知ウィンドウの上位のバーの部分に表示する。常に常駐するアプリに使える。

Notification.FLAG_NO_CLEAR
 通知をクリアを押してもクリアできないようにする FLAG_ACTIVITY_NEW_TASK ?

2012年1月29日日曜日

Notification

1.NotificationManager を取得する
 
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
2.Notificationオブジェクト生成
 
Notification notification = new Notification(
android.R.drawable.btn_default,
"通知情報が届きました",
System.currentTimeMillis());

・Notificationクラス
→通知情報のコンテキスト
 サウンド、バイブレーション、LEDを用いてアラートする事も
 引数1 icon 一覧に表示するアイコンID
 引数2 text 表示するテキスト
 引数3 表示する時間

3, PendingIntentを用意
 
Intent intent = new Intent(Intent.ACTION_VIEW);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
・PendingIntent
Intentを、タイミングを指定して発行することができるIntent。
時間を指定したり、イベント発生時に発行する。

4.通知情報の設定
 
notification.setLatestEventInfo(
getApplicationContext(),
"アプリ名",
"通知情報の説明文",
contentIntent);

5.一旦、Notificationを削除
 
nm.cancel(id)
6.Manager経由でNotify発行
 
nm.notify(R.string.app_name, notification);