現在説明一切ありません。
あとで入れます。
とりあえず書き忘れる前にコードだけ!
まず常駐型
// Intent の作成
Intent intent = new Intent(refreshService.this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(refreshService.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// LargeIcon の Bitmap を生成
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
// NotificationBuilderを作成
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
.setContentIntent(contentIntent)
// ステータスバーに表示されるテキスト
.setTicker("Text")
// アイコン
.setSmallIcon(R.drawable.ic_launcher)
// Notificationを開いたときに表示されるタイトル
.setContentTitle("Title")
// Notificationを開いたときに表示されるサブタイトル
.setContentText("SubTitle")
// Notificationを開いたときに表示されるアイコン
.setLargeIcon(largeIcon)
// 通知するタイミング
.setWhen(System.currentTimeMillis())
// 通知時の音・バイブ・ライト
.setDefaults(Notification.DEFAULT_SOUND
| Notification.DEFAULT_VIBRATE
| Notification.DEFAULT_LIGHTS);
// NotificationManagerを取得
NotificationManager manager = (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE);
manager.cancel(0);
startForeground(R.drawable.ic_launcher,builder.build());
通知型
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification = new NotificationCompat.Builder(this)
// アイコン
.setSmallIcon(R.drawable.ic_launcher)
// 通知バーに表示する簡易メッセージ
.setTicker("Title!")
// 時間
.setWhen(System.currentTimeMillis())
// 展開メッセージのタイトル
.setContentTitle("ContentTitle")
// 展開メッセージの詳細メッセージ
.setContentText("Message")
// PendingIntent
.setContentIntent(contentIntent)
// 通知時の音・バイブ・ライト
.setDefaults(Notification.DEFAULT_SOUND| Notification.DEFAULT_VIBRATE)
// タップするとキャンセル
.setAutoCancel(true)
.build();
notificationManager.notify(1, notification);
