2012-03-20 65 views
0

当手机振动时,有可能得到指示吗?我似乎无法找到任何信息....手机震动时如何获取通知?

+1

振动本身就是对一些事件occurence的通知。所以通知另一个通知似乎不合逻辑。 – Deepak 2012-03-20 08:41:58

+0

我同意@Deepak – Sameer 2012-03-20 09:27:30

回答

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); 

} 

,并使用相应的权限