Skip to content

Instantly share code, notes, and snippets.

@StelianMorariu
Created November 15, 2013 14:20
Show Gist options
  • Save StelianMorariu/7485046 to your computer and use it in GitHub Desktop.
Save StelianMorariu/7485046 to your computer and use it in GitHub Desktop.
Example of a notification with sound, lights and vibration
final Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
final Intent cancelIntent = new Intent(this, MHRCancelNotificationsActivity.class);
cancelIntent.putExtra(MyHeartRateKeys.CANCEL_NOTIFICATION, true);
cancelIntent.putExtra(MyHeartRateKeys.USER_ID, mUserId);
cancelIntent.putExtra(MyHeartRateKeys.NOTIFICATION_ID, ALERT_NOTIFICATION_ID);
cancelIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingCancel = PendingIntent.getActivity(this, 0, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT);
final Intent sessionActivityIntent = new Intent(this, MHRSessionActivity.class);
sessionActivityIntent.putExtra(MyHeartRateKeys.SERVICE_STARTED, true);
sessionActivityIntent.putExtra(MyHeartRateKeys.WORKOUT_TYPE_CODE, mWorkoutTypeCode);
sessionActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
final NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(R.drawable.mhr_logo);
builder.setContentText(getString(R.string.mhr_emergency_msg_notification));
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.mhr_launcher));
builder.setSound(soundUri);
builder.setVibrate(new long[]{2000});
builder.setTicker(getString(R.string.mhr_emergency_msg_notification));
builder.setAutoCancel(true);
builder.addAction(R.drawable.hdm_action_reset, getString(R.string.mhr_action_cancel), pendingCancel);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment