我一直在使用我正在構建的應用程序中的通知。構建通知的方式已經發生了很大變化,因爲它看起來很老,但最終我設法顯示了一個通知。 (*)手機在睡覺時在Android中發出通知
雖然我有兩個問題: 1)通知沒有聲音。這不是增加平板電腦上的通知量的問題,因爲例如來自gmail的通知確實會產生聲音。如何發出聲音和振動通知? (我正在嘗試在Android 6中使用)
2)更重要的是,即使手機正在睡眠時,如何發出「通知」我的通知?到目前爲止,我的通知做發生在手機正在睡覺時,但我必須打開手機才能看到它們。理想情況下,這些應該出現即使當屏幕是黑色的
編輯:只是要清楚,通知是在手機正在睡覺時發生。只是我沒有看到他們,除非我打開屏幕,他們是。我想對於通知「在屏幕上打開」
(*)我當前的代碼是
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(), 0);
Notification notification= new Notification.Builder(context)
.setContentTitle(message)
.setContentText("Proximity Alert!")
.setSmallIcon(R.mipmap.ic_launcher)
.setAutoCancel(true)
.setContentIntent(pi).build(); //getNotification();
//notification.flags= Notification.FLAG_AUTO_CANCEL;
//notification.setLatestEventInfo(context, "GAST", "Proximity Alert", pi); //this is deprecated
notificationManager.notify(NOTIFICATION_ID, notification);
聲音:URI defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);並在通知生成器:.setSound(defaultSoundUri) –