RSS

Multiline push notification in Android

03 Oct
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);
	}
Advertisements
 
Leave a comment

Posted by on October 3, 2015 in Android Source Code

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: