简体   繁体   中英

make android notification stay until user clears it

My question is regarding Notification and NotificationManager , in my app I use a Notification to alert the user, but it plays the mp3 I gave it only once, and vibrates only ones, I wish it to play a sound and vibrate until the user clear the Notification by pressing clear. I couldn't find an example that simplified it, what's the best way to achieve that?

Thank All that reply, Amitos80

there are flags you can set for achieving desired result,

Notification notification = new Notification(mIcon, mTickerText, mWhen);
notification.setLatestEventInfo(mContext, mContentTitle, mContentText, mContentIntent);
notification.defaults |= Notification.DEFAULT_SOUND; 
notification.flags = Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(ID, notification);

This will work definitely.

If you find it useful dont forget to mark it as an answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM