简体   繁体   English

科尔多瓦上的Android Lollipop通知图标setColor

[英]Android Lollipop Notification Icon setColor on Cordova

I'm trying to set background color for small icon color on Lollipop notification by modifying the default GCMIntentService.java from Cordova PushPlugin plugin : 我试图通过修改Cordova PushPlugin插件的默认GCMIntentService.java来为Lollipop通知中的小图标颜色设置背景色:

GCMIntentService.java GCMIntentService.java

[...]

import android.os.Build;

public void createNotification(Context context, Bundle extras)
{
    [...]

    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
            .setDefaults(defaults)
            .setWhen(System.currentTimeMillis())
            .setContentTitle(extras.getString("title"))
            .setTicker(extras.getString("title"))
            .setContentIntent(contentIntent)
            .setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mBuilder
            .setSmallIcon(R.drawable.notification_icon)
            .setColor(getResources().getColor(R.color.main));
    } else {
        mBuilder.setSmallIcon(R.drawable.icon);
    }

    [...]
}

[...]

colors.xml colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <color name="main">#009ee5</color>
</resources>

But, it doesn't work, the app crashes on build with the following error : 但是,它不起作用,该应用程序在构建时崩溃,并显示以下错误:

Error code 1 for command: ant with args: debug,-f,/Users/alex/Developpement/PhoneGap/myProject/platforms/android/build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
ERROR running one or more of the platforms: Error: /Users/alex/Developpement/PhoneGap/myProject/platforms/android/cordova/run: Command failed with exit code 8
You may not have the required environment or OS to run this project

If I comment "setColor" line, everything is fine (except the background color is missing), I just don't get why getColor make build fail. 如果我注释“ setColor”行,那么一切都很好(除了缺少背景色),我只是不明白为什么getColor使构建失败。 I'm using SDK 21. 我正在使用SDK 21。

EDIT : Updated sample code. 编辑:更新了示例代码。

I've managed to get this working by replacing /libs/android-support-v13.jar with the one from the Android SDK in /android-sdk-macosx/extras/android/support/v13/android-support-v13.jar 我设法通过将/libs/android-support-v13.jar替换为/libs/android-support-v13.jar的Android SDK中的/android-sdk-macosx/extras/android/support/v13/android-support-v13.jar

EDIT : I also had to replace android-support-vX.jar in the Facebook plugin libs folder. 编辑:我还必须替换Facebook插件libs文件夹中的android-support-vX.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM