如何在手机振动时收到通知?

时间:2012-03-20 08:20:14

标签: android vibrate

手机振动时是否可以获得指示?我似乎无法找到任何关于此的信息......

1 个答案:

答案 0 :(得分: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);

}

并使用适当的权限