トラッキング コード

2/15/2012

Problem of Custom Notification's Background Color, Android 4.0.3


Show a screenshot above.
ICS has problem of notification's background color, white.


Conditions the problem:
  1. set RemoteViews when Notificaiton created
  2. Application's targetSdkVersion is lower than "9"(=GingerBread).



Cause of the problem

Show frameworks source in Android-4.0.3_r1.

\frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone
- PhoneStatusBar.java




private boolean inflateViews(NotificationData.Entry entry, ViewGroup parent) {
        StatusBarNotification sbn = entry.notification;
        RemoteViews remoteViews = sbn.notification.contentView;
        if (remoteViews == null) {
            return false;
        }
                     :
                     :
                     :
        applyLegacyRowBackground(sbn, content);

        entry.row = row;
        entry.content = content;
        entry.expanded = expanded;
        entry.largeIcon = largeIcon;

        return true;
    }

    void applyLegacyRowBackground(StatusBarNotification sbn, View content) {
        if (sbn.notification.contentView.getLayoutId() !=
                com.android.internal.R.layout.status_bar_latest_event_content) {
            int version = 0;
            try {
                ApplicationInfo info = mContext.getPackageManager().getApplicationInfo(sbn.pkg, 0);
                version = info.targetSdkVersion;
            } catch (NameNotFoundException ex) {
                Slog.e(TAG, "Failed looking up ApplicationInfo for " + sbn.pkg, ex);
            }
            if (version > 0 && version < Build.VERSION_CODES.GINGERBREAD) {
                content.setBackgroundResource(R.drawable.notification_row_legacy_bg);
            } else {
                content.setBackgroundResource(R.drawable.notification_row_bg);
            }
        }
    }
Check to process of setting Notificaion Background Color.
if (version > 0 && version < Build.VERSION_CODES.GINGERBREAD) {
                content.setBackgroundResource(R.drawable.notification_row_legacy_bg);
            } else {
                content.setBackgroundResource(R.drawable.notification_row_bg);
            }


If TargetSdkVersion is lower than Build.VERSION_CODES.GINGERBREAD(APILevel9), set R.drawable.notification_row_legacy_bg!!


Check it!!

\frameworks\base\packages\SystemUI\res\drawable
- notification_row_legacy_bg.xml

\frameworks\base\packages\SystemUI\res\values\
- colors.xml

3 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, keep on updates
    motorola service center near me
    motorola mobile service centre in chennai
    moto g service center in chennai

    ReplyDelete