電話が振動したときに通知を受け取ることは可能ですか? これに関しては情報が見つからないようです....
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 に答える