Wednesday, 15 February 2012

android - Removing notification from a drawer after the sound is played and ticker displayed -


I want to remove a notification after displaying a notification as a ticker and after sound is played (And vibration too).

I have the following code in my app

  notification compat. Builder emulator = new notification compat. Builder (context) .setSmallIcon (R.drawable.ic_action_calendar_themedark) .setLights (0xffffffff, 500, 1000) .setAutoCancel (true) .setticker (context.getString (R.string.tewstgfd)); If (vibratePattern! = Null) {mBuilder.setVibrate (vibratePattern); } If (soundUri! = Null) {mBuilder.setSound (soundUri, AudioManager.STREAM_NOTIFICATION); } High-relativity high (mbuilder); Notification Manager Account Manager = (Notification Manager) context.getSystemService (reference. NETIFICATION_SERVICE); MNotificationManager.notify (R.string.e_notif_rest_id, mBuilder.build ()); MNotificationManager.cancel (R.string.e_notif_rest_id);   

Note the last 2 lines: I make the notification and delete it immediately. However, this notification also closes the sound and prevents vibration. So only one ticker is displayed, but it is not what I want at all. If I remove the last line (mNotificationManager.cancel (R.string.e_notif_rest_id), the notification remains in the drawer, but this is what I want to save.

What am I missing? < / P>

.cancel

  last notification manager Try to delay the mNotificationManager = ..... the rest of your code ... / may need to do this part in a background thread - Start MediaPlayer MP = new MediaPlayer (); AssetFileDescriptor d = context GetAssets (). OpenFd ( FileName); mp.reset (); mp.setDataSource (d.getFileDescriptor (), d.getStartOffset (), d.getLength ()); mp.prepare (); int duration = mp.getDuration (); mp.reset (); /// may need to perform this part in a background thread - end mNotificationManager.notify (R.string.e_notif_rest_id, mbuilder.build ()); new handler (). Post Delid (new Runnabel ) {@Override Public Zero Run () {mNotificationManager.cancel (R.string.e_notif_rest_id);}}, duration + 200 / * + 200ms * /);    

No comments:

Post a Comment