Skip to main content

Android - Notifications - 3 (Applying a big view style to a notification)

Big picture 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());  

Comments

  1. Hey ! It doesn't work in my app. No errors in the code but I don't have the extras line. it means no link with bigtext. my mail : mimeticsounds@gmail.com thank you for your reply !

    ReplyDelete

Post a Comment

Popular posts from this blog

Multi-Selection ListView ANDROID with CheckBox PART-2

Check Below Code : mainActivity.java package com.example.listviewcheckbox; import java.util.ArrayList; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { private ListView listview; ArrayList<String> items = new ArrayList<String>(); private int count; private boolean[] thumbnailsselection; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(...

Multi-Selection ListView ANDROID with CheckBox

Shaadi.com Indian Matrimonials Download code Create New Android Project: in res/layout/main.xml create new layout for list row : in res/layout/list_row.xml in your Main Activity Class: Create Class name mItems: Create New Class name SelectViewHolder: Create New Class name SelectArrayAdapter: Download Source Code Click Here : Check PART2 for more detail. Shaadi.com Matrimonials