3

I am using RemoteViews to create a custom notification. Is there any way to customize the Notification Area Specially Height...??? I don't want to use BigView coz i need use it for APIs less than 11.

The sanpshots are :

enter image description here enter image description here

Here is my code :

public class Main extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.notificationmain);

        Button bnotify = (Button) findViewById(R.id.notification);
        Button bcustomnotify = (Button) findViewById(R.id.customnotification);

        // Click For Default Notification       
        bnotify.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {
                Notification();
            }
        });

        // Click For Custom Notification
        bcustomnotify.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {
                CustomNotification();
            }
        });

    }

    // Default Notification
    public void Notification() {
        String strtitle = getString(R.string.notificationtitle);
        String strtext = getString(R.string.notificationtext);
        Intent intent = new Intent(this, NotificationView.class);
        intent.putExtra("title", strtitle);
        intent.putExtra("text", strtext);

        PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.logosmall)
                .setTicker(getString(R.string.notificationticker))
                .setContentTitle(getString(R.string.notificationtitle))
                .setContentText(getString(R.string.notificationtext))
                .addAction(R.drawable.ic_launcher, "Action Button", pIntent)
                .setContentIntent(pIntent)
                .setAutoCancel(true);

        // Create Notification Manager
        NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationmanager.notify(0, builder.build());
    }


    // Custom Notification

    public void CustomNotification() {
        // Using RemoteViews to bind custom layouts into Notification
        RemoteViews remoteViews = new RemoteViews(getPackageName(),
                R.layout.customnotification);

        String strtitle = getString(R.string.customnotificationtitle);
        String strtext = getString(R.string.customnotificationtext);

        Intent intent = new Intent(this, NotificationView.class);
        intent.putExtra("title", strtitle);
        intent.putExtra("text", strtext);

        PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.logosmall)
                .setTicker(getString(R.string.customnotificationticker))
                .setAutoCancel(true)
                .setContentIntent(pIntent)
                .setContent(remoteViews);

        remoteViews.setImageViewResource(R.id.imagenotileft,R.drawable.ic_launcher);
        remoteViews.setImageViewResource(R.id.imagenotiright,R.drawable.androidhappy);

        remoteViews.setTextViewText(R.id.title,getString(R.string.customnotificationtitle));
        remoteViews.setTextViewText(R.id.text,getString(R.string.customnotificationtext));

        Calendar cal = Calendar.getInstance();
        cal.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("hh:mm a");

        remoteViews.setTextViewText(R.id.time,sdf.format(cal.getTime()) );
        NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationmanager.notify(1, builder.build());
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}
BST Kaal
  • 2,993
  • 6
  • 34
  • 52
  • You can control the height by modifying the layout `customnotification`, and use a smaller sized image. – Joel Fernandes Jun 19 '14 at 06:01
  • I want to increase the height... – BST Kaal Jun 19 '14 at 06:03
  • The height available for a custom notification layout depends on the notification view. Normal view layouts are limited to `64 dp`, and expanded view layouts are limited to `256 dp`. – M D Jun 19 '14 at 06:04
  • @JoelFernandes , I increased the image frame size to 80dp in my `customnotification` layout, but still the height is same... – BST Kaal Jun 19 '14 at 06:09

2 Answers2

2

It looks like Android support library v4 has a notification builder that supports this sort of thing: http://developer.android.com/reference/android/support/v4/app/NotificationCompat.InboxStyle.html

NotificationCompat.InboxStyle appears to be the BigView equivalent for pre-4.1 devices.

This allows you to create a larger notification with up to five lines of text, which may suit your needs.

 Notification noti = new Notification.Builder()
 .setContentTitle("5 New mails from " + sender.toString())
 .setContentText(subject)
 .setSmallIcon(R.drawable.new_mail)
 .setLargeIcon(aBitmap)
 .setStyle(new Notification.InboxStyle()
     .addLine(str1)
     .addLine(str2)
     .setSummaryText("+3 more"))
 .setContentTitle("")
 .build();

Here's a short tutorial: http://doandroidcoding.blogspot.com/2014/01/bigview-style-notification.html?m=1

IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147
bstar55
  • 3,542
  • 3
  • 20
  • 24
0

Notification display area is system controlled in android please refer this link

Himanshu Agarwal
  • 4,623
  • 5
  • 35
  • 49
santosh kumar
  • 1,465
  • 3
  • 13
  • 14