android-discuss icon indicating copy to clipboard operation
android-discuss copied to clipboard

[问答]魅族 notification 状态栏icon 设置无效

Open EvilMouth opened this issue 9 years ago • 14 comments

notification状态栏通知,设置smallIcon后,其他手机icon显示正常,魅族手机上icon显示失效,显示的是下面这张: 382bb0f4-4240-43ca-ac42-53b6f810a3d9 why?

EvilMouth avatar Jan 11 '16 08:01 EvilMouth

魅族手机在适配上有些东西确实比较麻烦,不过魅族显然自己知道这一点,所以兄弟,看到这个你会很开心!Flyme API

lumenghz avatar Jan 11 '16 08:01 lumenghz

@lubeast 兄弟,已经看过了那个api,demo也只是说设置白色圆圈progressBar而已。就是我自己setSmallIcon自己的图标,但是失效,其他手机就不会

EvilMouth avatar Jan 11 '16 09:01 EvilMouth

@yuhangjiayou 并没有只说了设置白色圆圈类型的progressbar

final Notification.Builder builder = new Notification.Builder(context);
builder.setLargeIcon(mIcon)
.setSmallIcon(R.drawable.ic_launcher)
.setTicker("CirlceProgressBarNotification")
.setContentTitle("ContentTitle")
.setContentInfo("ContentInfo") 
.setContentText("ContentText")
.setWhen(0)
.setOngoing(true);

代码中有setSmallIcon(R.drawable.ic_launcher)不能用吗?还有,你导入了api提供的jar包了吗?

lumenghz avatar Jan 11 '16 09:01 lumenghz

@lubeast 运行了官方的demo了,setSmallIcon(R.drawable.ic_launcher)这里设置的icon是应用的launcher,但是实际跑出来显示的icon却是我上面发的那个图片

EvilMouth avatar Jan 11 '16 09:01 EvilMouth

@yuhangjiayou 我刚也运行了,魅族手机上确实显示的是这个图标,非魅族就可以,我也不知道了。。抱歉 :D

lumenghz avatar Jan 11 '16 10:01 lumenghz

我用魅族手机测试notification的时候也遇到了奇怪的问题。icon只能显示应用图标。设置SmallIcon或者LargeIcon都没有效果。只能用自定义notification来解决了。

Fan0932 avatar Jan 26 '16 02:01 Fan0932

@Fan0932 你怎么设置的,使icon不显示一楼的默认图标而显示应用图标的啊?

imkkdev avatar Jan 26 '16 13:01 imkkdev

这个问题不仅魅族有,华为的某些比较新的机型也有的。系统适配问题,为了保持通知栏统一,直接拿的应用图标作为smallIcon,这个问题暂时无解

icespring avatar Jan 28 '16 02:01 icespring

@pcqpcq 没有进行什么设置,在魅族手机上进行测试的时候发现通知栏如果不使用remoteview,那么左边icon部分就会显示为应用的icon。比较蛋疼

Fan0932 avatar Jan 28 '16 02:01 Fan0932

乐视1s手机也有这问题设置samllicon无效

huopochuan avatar Apr 23 '16 01:04 huopochuan

我也碰到了这个问题 有什么比较好的解决方案吗

shexianseng avatar Jun 06 '17 06:06 shexianseng

魅族应该是定制了Flyme的通知,如果要启用的话,有用的没有的都要设置了才行;

final Notification.Builder builder = new Notification.Builder(context);
builder.setLargeIcon(mIcon)
.setSmallIcon(R.drawable.ic_launcher)
.setTicker("CirlceProgressBarNotification")
.setContentTitle("ContentTitle")
.setContentInfo("ContentInfo") 
.setContentText("ContentText")
.setWhen(0)
.setOngoing(true);

这些都得加上。。。。

fangwenjie avatar Jul 05 '17 01:07 fangwenjie

@izyhang 这是魅族的用苦良心,避免假应用伪造高频率应用的推送样式来引诱用户点击激活应用。

但我是个正经人,正经得经不住产品同学的威逼利诱,苦苦相逼!! 我也碰到同样的问题了,然后连断点、边尝试,试出来了...

    //反射设置该应用为flyme系统内部应用,用于支持自定义状态栏小图标、通知栏大图标, code from sodino
    public static void flymeNotification(Notification notification, Bitmap largeIcon) {
        boolean internalApp = true;
        //设置该应用为系统内部应用,用于支持自定义状态栏小图标, code from sodino
        try {
            if (mFlymeNotification == null) {
                mFlymeNotification = Notification.class.getDeclaredField("mFlymeNotification");
            }
            if (mInternalApp == null) {
                Class<?> NotificationExt = Class.forName("android.app.NotificationExt");
                mInternalApp = NotificationExt.getDeclaredField("internalApp");
                mInternalApp.setAccessible(true);

                mNotificationBitmapIcon = NotificationExt.getDeclaredField("notificationBitmapIcon");
                mNotificationBitmapIcon.setAccessible(true);
            }


            Object flymeNotification = mFlymeNotification.get(notification);
            // 标识为内部应用,允许自定义smallIcon, code from sodino
            mInternalApp.set(flymeNotification, internalApp ? 1 : 0);

            // 反射:设置大图标,等同于Notification.Builder.setLargeIcon(bitmap)
            mNotificationBitmapIcon.set(flymeNotification, largeIcon);
        } catch (Exception e) {
            PushkitUtil.log().e("flymeNotification", e);
        }
    }

关键的断点分析代码如下: https://wx2.sinaimg.cn/mw690/e3dc9ceagy1fmt4tfzxfyj218w0kuae3.jpg debug.flyme


12.27更新 smallIcon在魅蓝m2 note android 5.1生效,但在魅蓝m5 note android 7.0就不生效了 largeIcon还是一直生效的

sodino avatar Dec 25 '17 09:12 sodino

@sodino 系统状态栏的smallIcon是通过哪个字段修改的?

aishang5wpj avatar May 16 '18 13:05 aishang5wpj