2012-03-20 8 views
0

携帯電話が振動したときに表示することはできますか?私はこれについての情報を見つけることはできません....電話が振動すると通知を受け取る方法は?

+1

振動を使用するいくつかのイベントの出現に通知します。したがって、別の通知の通知は論理的ではないようです。 – Deepak

+0

私は@Deepakに同意します – Sameer

答えて

1

私はこの方法を試みたことがない。私は知らない正しく動作しているか間違っているか

AudioManagerでgetRingerMode()メソッドを使用します。

AudioManager am =(AudioManager)getSystemService(Context.AUDIO_SERVICE);

switch (am.getRingerMode()) { 

    case AudioManager.RINGER_MODE_VIBRATE: 
     Log.i("MyApp","Vibrate mode"); 
     displayNotification("Hi i am notification"); 
     break; 

} 

......

public void displayNotification(String msg) 
{ 
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
Notification notification = new Notification(R.drawable.icon, msg, System.currentTimeMillis()); 

// The PendingIntent will launch activity if the user selects this notification 
PendingIntent contentIntent = PendingIntent.getActivity(this, REQUEST_CODE, new Intent(this, ExpandNotification.class), 0); 

notification.setLatestEventInfo(this, "Title here", ".. And here's some more details..", contentIntent); 

manager.notify(NOTIFICATION_ID, notification); 

} 

自体に適切な権限

関連する問題