让android通知保持不变,直到用户清除它

让android通知保持不变,直到用户清除它,android,notifications,alert,Android,Notifications,Alert,我的问题是关于通知和NotificationManager, 在我的应用程序中,我使用通知提醒用户,但它只播放我给它的mp3一次,并且只振动一次,我希望它播放声音并振动,直到用户按clear清除通知。我找不到一个简化的例子,实现这一点的最佳方法是什么 谢谢你的回答, Amitos80您可以设置一些标志以实现所需的结果 Notification notification = new Notification(mIcon, mTickerText, mWhen); notification.setL

我的问题是关于通知和
NotificationManager
, 在我的应用程序中,我使用通知提醒用户,但它只播放我给它的mp3一次,并且只振动一次,我希望它播放声音并振动,直到用户按clear清除通知。我找不到一个简化的例子,实现这一点的最佳方法是什么

谢谢你的回答,
Amitos80

您可以设置一些标志以实现所需的结果

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);
这肯定会奏效的


如果你觉得它有用,别忘了把它标记为答案。

你可以设置一些标志来达到预期的结果

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);
这肯定会奏效的

如果你觉得它有用,别忘了把它标记为答案。

“这肯定有用。”--不,不会。它应该是
Notification.FLAG_AUTO_CANCEL | Notification.FLAG_persistent
。第一个标志处理“直到用户按clear清除通知”部分。第二个标志处理“我希望它播放声音并振动,直到用户清除通知”部分。“这肯定管用。”——不,不会的。它应该是
Notification.FLAG_AUTO_CANCEL | Notification.FLAG_persistent
。第一个标志处理“直到用户按clear清除通知”部分。第二个标志处理“我希望它播放声音并振动,直到用户清除通知”部分。