Tuesday, January 31, 2017

Multiline push notification in Android

 int mNotificationId = 001;  
 private void generateNotification(Context mContext, String message) {  
  Intent notificationIntent = new Intent(mContext, MainActivity.class);  
  // set intent so it does not start a new activity  
  notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);  
  PendingIntent resultPendingIntent =  
  PendingIntent.getActivity(mContext, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);  
  NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext);  
  Notification notification = mBuilder.setSmallIcon(R.drawable.alert).setTicker(getResources().getString(R.string.app_name)).setWhen(0)  
  .setAutoCancel(true)  
  .setContentTitle(getResources().getString(R.string.app_name))  
  .setStyle(new NotificationCompat.BigTextStyle().bigText(message))  
  .setContentIntent(resultPendingIntent)  
  .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))  
  .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_logo))  
  .setContentText(message).build();  
  NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);  
  notificationManager.notify(mNotificationId, notification);  
 }  

No comments :

Post a Comment