Skip to main content
Samsung Developer Program

Example Code - Hello Rich Notification

Example code for an introductory rich notification message

Hello Rich Notification is sample code that introduces the Rich Notification integration.

public class HelloRichNotificationActivity extends Activity implements SrnRichNotificationManager.EventListener {
   private SrnRichNotificationManager mRichNotificationManager;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      // Creates an instance of Srn.
      Srn srn = new Srn();
      try {
         // Initializes an instance of Srn.
         srn.initialize(this);
      } catch (SsdkUnsupportedException e) {
         // Handles errors
      }

      mRichNotificationManager = new SrnRichNotificationManager(this);

      // Starts the manager.
      mRichNotificationManager.start();

      Bitmap bgBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.noti_bg);
      Bitmap myAppIconBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

      SrnRichNotification myRichNotification = new SrnRichNotification(this);

      SrnImageAsset myAppIcon = new SrnImageAsset(this, "app_icon", myAppIconBitmap);
      myRichNotification.setIcon(myAppIcon);

      myRichNotification.setTitle("Raptors vs. Nets");

      SrnStandardTemplate myPrimarySection = new SrnStandardTemplate(HeaderSizeType.MEDIUM);
      SrnImageAsset myBackgroundImage = new SrnImageAsset(this, "noti_background", bgBitmap);      
      myPrimarySection.setBackgroundImage(myBackgroundImage);

      myPrimarySection.setSubHeader("Today at 5 PM");
      myPrimarySection.setBody("NBA finals pits Raptors against the Nets in game 6.");

      myRichNotification.setPrimaryTemplate(myPrimarySection);

      SrnRemoteLaunchAction myAction = new SrnRemoteLaunchAction("Check In");

      Bitmap checkInIconBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_check_in);
      SrnImageAsset checkInIcon = new SrnImageAsset(this, "checkin_icon", checkInIconBitmap);
      myAction.setIcon(checkInIcon);

      myAction.setPackage("com.mypackage.myapp");
      myAction.setData(Uri.parse("checkin://venue_id=12345"));

      Intent resultIntent = new Intent(this, CallbackActivity.class);
      myAction.setCallbackIntent(CallbackIntent.getActivityCallback(resultIntent));

      myRichNotification.addActionWithPermissionCheck(myAction);
      myRichNotification.setAlertType(AlertType.SOUND_AND_VIBRATION, PopupType.NORMAL);

      mRichNotificationManager.notify(myRichNotification);

      // Stops the manager.
      mRichNotificationManager.stop(); 

   }

   @Override
   protected void onResume() {
      super.onResume();

      mRichNotificationManager.registerRichNotificationListener(this);
   }

   @Override
   protected void onPause() {
      super.onPause();

      mRichNotificationManager.unregisterRichNotificationListener(this);
   }

   @Override
   public void onRemoved(UUID uuid) {
   }

   @Override
   public void onRead(UUID uuid) {
   }

   @Override
   public void onError(UUID uuid, ErrorType error) {
   }
} 

 

  • Was this article helpful?