Android notification 通知で青いLEDを0.1秒ごとに点滅させるサンプル
notificationとは、Androidアプリのシステムトレイと呼ばれる上部の部分にアイコンを表示させたり、する機能です。
新しいインテントを立ち上げる、なども含まれています。
defaultsを使ってもLEDが点滅しなかったので、青いLEDを0.1秒ごとに点滅させる、というふうに決め打ちしました。
private static void generateNotification(Context context, String message) {
//システムトレイに通知するアイコン
int icon = R.drawable.ic_stat_gcm;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
//ステータスバーをクリックした時に立ち上がるアクティビティ
Intent notificationIntent = new Intent(context, OfferDisplayActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
//通知の種類 音 バイブにしている時は鳴らない
notification.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE ;
notification.flags = Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_AUTO_CANCEL ;
notification.ledOnMS = 100;
notification.ledOffMS = 100;
notification.ledARGB = Color.BLUE;
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notification);
}
