NotificationManager nmng = (NotificationManager)context.getSystemService(NOTIFICATION_SERVICE); Notification.Builder nb = new Notification.Builder(context) .setPriority(Notification.PRIORITY_HIGH) // 高優先の表示 .setContentTitle("バッテリー") // 通知領域に表示されるタイトル .setContentText("battery : " + batteryLevel) // 通知領域に表示されるテキスト .setSmallIcon(R.drawable.icon); // ステータスバー、通知領域に表示されるアイコン nmng.notify(0, nb.build()); // NotificationManagerに登録
Intent intent = new Intent(context.getBaseContext(), TargetActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context.getBaseContext(), 0, intent, 0); Notification.Builder nb = new Notification.Builder(sv) .setContentTitle("バッテリー") .setContentText("battery : " + batteryLevel) .setSmallIcon(R.drawable.icon) .setContentIntent(pendingIntent); // タップ時のインテント設定 nmng.notify(0, nb.build()); // NotificationManagerに登録
Notification.Builder nb = new Notification.Builder(context) .setSmallIcon(R.drawable.res); // R.drawable.res : LevelListDrawable, LayerDrawable を指定する。
// LayerDrawable の Drawable を取得 Resources r = context.getResources(); LayerDrawable layerList = (LayerDrawable)r.getDrawable(R.drawable.layer_list); // LayerDrawableのリソース Drawable drawable = (Drawable)r.getDrawable(R.drawable.iconB); layerList.setDrawableByLayerId(R.id.icon00, drawable); // layerList内の "icon00" と名付けられているアイコンを drawable のものに置き換え layerList.invalidateSelf(); // 更新処理?
Big Picture Notification | ビットマップ画像の表示 |
Big Text Notification | 複数行のテキストオブジェクトの表示 |
Inbox Style Notification | テキストのリスト、メッセージ、見出しなど |