0

For some reason, I don't get to use android-support-library in my code. In order to perform a Notification that matches Android 4.0 style, I write this:

private void noti() {
    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    int icon = R.drawable.ic_launcher;
    CharSequence text = "Notification Text";
    CharSequence contentTitle = "Notification Title";
    CharSequence contentText = "Sample notification text.";
    long when = System.currentTimeMillis();
    Intent intent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
    Notification notification = new Notification(icon,text,when);
    notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);
    notificationManager.notify(1, notification);
}

How to control the progress bar in it? The way in developer.google.com is using Notification.Builder, but Builder is in the android-support-library.

I found another way to do this is

notification.setProgressBar(int viewId, int max, int progress, boolean indeterminate)

But another problem is that it needs a custom notification layout which contains a progress bar. If I use a custom layout, it won't match android 4.0 style.

What can I do now? Please help me, Thanks!

Tim S. Van Haren
  • 8,861
  • 2
  • 30
  • 34
John
  • 74
  • 2
  • 9
  • I don't understand what you're asking for: do you want a custom layout or a layout that matches android 4.0 style? I usually use `notif.setProgress(max, progress, indeterminate)` to update the progress bar in my notification. This uses the system's default style. – Joffrey Aug 06 '13 at 21:54
  • @Joffrey Thanks for comment. I need my Notification to match android 4.0 style , for witch reason I can't use a custom layout. notif.setProgress(max, progress, indeterminate) is a method of Notification.Builder witch is in the android-support-library . but thanks anyway ^ – John Aug 07 '13 at 01:39
  • My bad, I read "I need a custom layout" instead of "it needs" ^^ Well `NotificationCompat.Builder` is in the support, but isn't `Notification.Builder` directly in the system library? If you want some special features such as a progress bar, then it seems logical to me to use the Builder's possibilities. If you want backwards compatibility, then the support library is here. – Joffrey Aug 07 '13 at 05:30

1 Answers1

0

I solved the problem by using a custom layout witch came from android source code here , so it looks like a system Notification. Hope this can help others.

John
  • 74
  • 2
  • 9