我正在尝试通过修改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 make build失败。 我正在使用SDK 21。
编辑: 更新了示例代码。
答案 0 :(得分:2)
我已经设法通过将/libs/android-support-v13.jar
替换为/android-sdk-macosx/extras/android/support/v13/android-support-v13.jar
android-support-vX.jar
来实现此目的
编辑:我还必须替换Facebook插件libs文件夹中的{{1}}。