package notification.pop;
//import android.support.v4.app.NotificationCompact;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
- (省略)
//PendingIntentの発行
/*
Intentはアプリケーションの目的を
Activity, Service, Broadcastに伝える為に使われる
PnedingIntentとは
あるタイミングで発行されるIntentを発行する為に使われる
あるタイミングとは
時間を指定して発行
イベントの発生時に発行
?: PendingIntentを使う必要性。
第4引数のFLAGは、PendingIntentが発行された時、
一度用意してあるPendingIntentの扱いを指定するもの?
FLAG_CANCEL_CURRENT 新しく作るけど前のはキャンセルするべき
FLAG_NO_CREATE 新しく作らない?つくろうとする?
FLAG_ONE_SHOT 一度発行されていれば再発行しない
FLAG_UPDATE_CURRENT 既にあればそれを使いまわす?
*/
PendingIntent pIntent = PendingIntent.getActivity(
this, 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
//NotificationManagerの定義
NotificationManager manager =
(NotificationManager) this.getSystemService(Service.NOTIFICATION_SERVICE);
//Builderの定義
Notification.Builder builder = new Notification.Builder(this);
builder.setContentIntent(pIntent);
//ステータスバーに表示されるアイコン
builder.setSmallIcon(R.drawable.ic_small);
//ステータスバーの展開時に表示されるアイコン
builder.setLargeIcon(R.drawble.ic_large);
builder.setAutoCancel(true);
//ステータスバーに表示される文字列
builder.setTicker("pop notice!!");
//ステータスバーの展開時に表示されるタイトル文字列
builder.setContentTitle("content title.");
//ステータスバーの展開時に表示される詳細文字列
builder.setContentText("content text.");
//通知をPOP
manager.notify(0, builder.build());