int icon = R.drawable.icon;
Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Countdown Complete!";
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent();
Notification notification = new Notification(icon, "is completed!", System.currentTimeMillis());
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, contentTitle, contentText, pendingIntent);
long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;
notificationManager.notify(myCountDown.getId(), notification);
此代碼在我的android應用程序中,我收到通知但沒有聲音或振動。Android通知不會發出聲音或振動
我已經在多個電話上測試過,所有聲音和振動都在設置中打開並打開。我還相信,我所要求使用的振動允許在Android清單,但我仍然只能得到通知...
我也試過:
notification.defaults = Notification.DEFAULT_ALL;
和
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;
如何在通知中獲得聲音和振動?
很抱歉忘記了這一點,但我試過Notification.DEFAULTS_ALL和VIBRATE,但仍然沒有任何... – vbman11 2012-01-26 22:45:19
和我剛剛編輯添加這些 – vbman11 2012-01-26 23:03:22
您嘗試創建您的意圖,如在文檔中Intent notificationIntent = new Intent (this,MyClass.class); – 2012-01-27 16:20:24