Question
I'm using RichNotification from Samsung Accessory Library to send notifications from an Android phone to Gear S2. When the user taps the notification icon, it successfully launches a Tizen app on the Gear S2. However, the notification remains visible even after the app launches.
How can I make the notification automatically close when the user taps its icon? Below is my Android code implementation:
mRichNotificationManager = new SrnRichNotificationManager(getApplicationContext());
mRichNotificationManager.start();
SrnRichNotification myRichNotification = new SrnRichNotification(this);
Bitmap myAppIconBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
SrnImageAsset myAppIcon = new SrnImageAsset(this, "app_icon", myAppIconBitmap);
myRichNotification.setIcon(myAppIcon);
myRichNotification.setTitle("Raptors vs. Nets");
SrnStandardTemplate myPrimaryTemplate = new SrnStandardTemplate(SrnStandardTemplate.HeaderSizeType.MEDIUM);
myRichNotification.setPrimaryTemplate(myPrimaryTemplate);
SrnRemoteLaunchAction myAction = new SrnRemoteLaunchAction("Check In");
Bitmap checkInIconBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.listen);
SrnImageAsset checkInIcon = new SrnImageAsset(this, "checkin_icon", checkInIconBitmap);
myAction.setIcon(checkInIcon);
myAction.setPackage("org.example.multiview");
Bundle bundle = new Bundle();
bundle.putString("message","data from phone");
myAction.setExtras(bundle);
myRichNotification.addActionWithPermissionCheck(myAction);
myRichNotification.setAlertType(SrnRichNotification.AlertType.SOUND_AND_VIBRATION, SrnRichNotification.PopupType.NORMAL);
mRichNotificationManager.notify(myRichNotification);
mRichNotificationManager.stop();
Answer
Problem Understanding
The issue occurs when using Samsung Accessory Library's RichNotification feature. While the notification successfully triggers the Tizen app launch on Gear S2, the notification persists rather than automatically closing after the app launch.
Solution Methods
-
Using dismissAll() method:
- Call
dismissAll()before stopping the notification manager - This method dismisses all active rich notifications
- Implementation:
mRichNotificationManager.notify(myRichNotification); mRichNotificationManager.dismissAll(); mRichNotificationManager.stop();
- Call
-
Alternative approach:
- Implement a callback mechanism in your Tizen app
- When the app launches, send a signal back to the Android device
- Have the Android device dismiss the specific notification upon receiving this signal
Code Examples
Here's the corrected implementation for automatic dismissal:
// After setting up your notification
mRichNotificationManager.notify(myRichNotification);
// Add dismissAll() before stopping the manager
mRichNotificationManager.dismissAll();
mRichNotificationManager.stop();
Additional Tips
- Ensure your notification has a unique ID if you're managing multiple notifications
- Test the notification flow thoroughly as timing issues might affect dismissal
- Consider implementing error handling for cases where the notification might fail to dismiss
- For more complex scenarios, you might need to implement a custom notification dismissal protocol between your Android and Tizen apps