Skip to content

Instantly share code, notes, and snippets.

@Debashis-Sinha
Created August 12, 2018 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Debashis-Sinha/cd5b9d9107665cc5ca33b0e5daeda6fe to your computer and use it in GitHub Desktop.
Save Debashis-Sinha/cd5b9d9107665cc5ca33b0e5daeda6fe to your computer and use it in GitHub Desktop.
Android show notification
private void sendNotification(String messageBody, String webUrl) {
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("targetLink",webUrl);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(getString(R.string.app_name))
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment