Big picture style
Big text style
Inbox style
Bitmap icon1 = BitmapFactory.decodeResource(getResources(),
R.drawable.dhaval1);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setAutoCancel(true)
.setContentTitle("DJ-Android notification")
.setSmallIcon(R.drawable.ic_launcher).setLargeIcon(icon1)
.setContentText("Hello World!");
NotificationCompat.BigPictureStyle bigPicStyle = new NotificationCompat.BigPictureStyle();
bigPicStyle.bigPicture(icon1);
bigPicStyle.setBigContentTitle("Dhaval Sodha Parmar");
mBuilder.setStyle(bigPicStyle);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, testActivity.class);
// The stack builder object will contain an artificial back stack for
// the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(testActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(100, mBuilder.build());
Big text style
Bitmap icon1 = BitmapFactory.decodeResource(getResources(),
R.drawable.dhaval1);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setAutoCancel(true)
.setContentTitle("DJ-Android notification")
.setSmallIcon(R.drawable.ic_launcher).setLargeIcon(icon1)
.setContentText("Hello World!");
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
bigText.bigText("Android is a Linux-based operating system designed primarily for touchscreen mobile devices such as smartphones and tablet computers. Initially developed by Android, Inc., which Google backed financially and later bought in 2005,[12] Android was unveiled in 2007 along with the founding of the Open Handset Alliance: a consortium of hardware, software, and telecommunication companies devoted to advancing open standards for mobile devices.[13] The first Android-powered phone was sold in October 2008");
bigText.setBigContentTitle("Android");
bigText.setSummaryText("By: Dhaval Sodha Parmar");
mBuilder.setStyle(bigText);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, testActivity.class);
// The stack builder object will contain an artificial back stack for
// the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(testActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(100, mBuilder.build());
Inbox style
String[] events = new String[6];
events[0] = "Helloo..!";
events[1] = "How are you?";
events[2] = "HIII !!";
events[3] = "i am fine...";
events[4] = "what about you? all is well?";
events[5] = "Yes, every thing is all right..";
Bitmap icon1 = BitmapFactory.decodeResource(getResources(),
R.drawable.dhaval1);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setAutoCancel(true)
.setContentTitle("DJ-Android notification")
.setSmallIcon(R.drawable.ic_launcher).setLargeIcon(icon1)
.setContentText("Hello World!");
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
// Sets a title for the Inbox style big view
inboxStyle.setBigContentTitle("Event Details");
// Moves events into the big view
for (int i = 0; i < events.length; i++) {
inboxStyle.addLine(events[i]);
}
// Moves the big view style object into the notification object.
mBuilder.setStyle(inboxStyle);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, testActivity.class);
// The stack builder object will contain an artificial back stack for
// the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(testActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(100, mBuilder.build());
Belum ada tanggapan untuk "Android - Notifications - 3 (Applying a big view style to a notification)"
Post a Comment