0

手机震动时是否有提示?我似乎找不到任何关于此的信息......

4

1 回答 1

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

}

并使用适当的权限

于 2012-03-20T08:38:40.067 回答