Android Cordova 上的棒棒糖通知图标 setColor
Android Lollipop Notification Icon setColor on Cordova
我正在尝试通过修改 Cordova PushPlugin 插件的默认 GCMIntentService.java 来为 Lollipop 通知上的小图标颜色设置背景颜色:
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
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="main">#009ee5</color>
</resources>
但是,它不起作用,应用程序在构建时崩溃并出现以下错误:
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
如果我评论 "setColor" 行,一切都很好(除了缺少背景颜色),我只是不明白为什么 getColor 使构建失败。
我正在使用 SDK 21。
编辑:
更新了示例代码。
我已通过将 /libs/android-support-v13.jar
替换为 /android-sdk-macosx/extras/android/support/v13/android-support-v13.jar
中 Android SDK 中的那个来成功实现此功能
编辑: 我还必须替换 Facebook 插件库文件夹中的 android-support-vX.jar
。
我正在尝试通过修改 Cordova PushPlugin 插件的默认 GCMIntentService.java 来为 Lollipop 通知上的小图标颜色设置背景颜色:
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
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="main">#009ee5</color>
</resources>
但是,它不起作用,应用程序在构建时崩溃并出现以下错误:
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
如果我评论 "setColor" 行,一切都很好(除了缺少背景颜色),我只是不明白为什么 getColor 使构建失败。 我正在使用 SDK 21。
编辑: 更新了示例代码。
我已通过将 /libs/android-support-v13.jar
替换为 /android-sdk-macosx/extras/android/support/v13/android-support-v13.jar
编辑: 我还必须替换 Facebook 插件库文件夹中的 android-support-vX.jar
。