0
當手機振動時,有可能得到指示嗎?我似乎無法找到任何信息....手機震動時如何獲取通知?
當手機振動時,有可能得到指示嗎?我似乎無法找到任何信息....手機震動時如何獲取通知?
我從來沒有嘗試過這種方法。我不知道是否工作正常或錯誤。
在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);
}
,並使用相應的權限
振動本身就是對一些事件occurence的通知。所以通知另一個通知似乎不合邏輯。 – Deepak 2012-03-20 08:41:58
我同意@Deepak – Sameer 2012-03-20 09:27:30