コードハイライト用

せっかく無職になったから、働いてる時に忙しくて出来なかった色々な事をやってみようと場当たり的に始めたブログ。 だったけど就職決まっちゃいました。

2012年2月15日水曜日

[Android] 通知でバイブレーションさせる

デフォルトで通知出せばバイブレーションするもんだと思ったけど
そのままではダメだったのでメモ。
ソースから直接メソッド切り抜いただけですが。

/** 通知を出す */
private void setNotification( CharSequence notifyMsg, CharSequence contextMsg, Intent intent) {

 Notification notification = new Notification(R.drawable.test, notifyMsg, System.currentTimeMillis());

 PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
 notification.setLatestEventInfo(
   getApplicationContext(),
   getText(R.string.app_name),
   contextMsg,
   pIntent);

 //
 // バイブ設定
 // long の配列の場合、単位はミリ秒で {無振動, 振動, 無振動, 振動 ... } と指定する。
 // システムのデフォルトの振動方式を使用する場合は、デフォルト値を使用する旨をフラグで指定。
 // 
 //notification.vibrate = new long[] {0, 500, 0, 1000, 0};
 notification.defaults |= Notification.DEFAULT_VIBRATE;

 NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
 nm.notify(1111, notification);
}

0 件のコメント:

コメントを投稿