那么,有人知道是否有一种方法可以使用PushPlugin启用备用通知图标吗? 还是说我必须使用启动器图标或者使用另一个具有此功能的插件?
谢谢!
我从未使用过Phonegap构建工具-我在自己的计算机上手动完成构建过程。不管怎样,我认为你应该在src/com/plugin/gcm下找到GCMIntentService.java文件。在那个文件中,搜索以下代码行:
.setSmallIcon(context.getApplicationInfo().icon)
这可以被您想要的图标所替换。如果您将名为“notification.png”的图标放置在/res/drawable文件夹中,您可以将代码行更改为:
.setSmallIcon(your.package.name.R.drawable.notification);
mdpi - 22x22 area in 24x24
hdpi - 33x33 area in 36x36
xhdpi - 44x44 area in 48x48
xxhdpi - 66x66 area in 72x72
xxxhdpi - 88x88 area in 96x96
var push = PushNotification.init({
"android": {
"senderID": "<<SENDER_ID>>",
"icon": "myicon",
"iconColor": "#123456"
},
在您的推送有效负载中,现在可以通过添加“image”参数来覆盖向下滑动时指定的图标。Image可以是资源,可以引用“www/image/image.png”,也可以是完整的URL。
"插件文档"非常出色,我建议阅读它们。希望这对某些人有用。
在你的PhoneGap或Cordovaconfig.xml中设置此项
<preference name="android-targetSdkVersion" value="20"/>
Android API 21+ 仅使用白色作为小图标的颜色。 改变目标 SDK 版本会使编译器使用旧的 SDK,因此您将无法使用新的 SDK 功能。 所以最好的方法是拥有两个图标:小图标和大图标(当下拉栏时)
使用此工具为我的logo图像(假设它的名称为“notif.png”)生成不同大小,该图像具有透明背景。请记住要使用透明背景图像,如果没有透明图像,Android将只显示白色图标。假设生成的图标名称为“ic_notif”。
将相应大小的图像复制到res/drawables文件夹中。
在推送JS代码中,将“icon”属性的值设置为“ic_notif”。并将“iconColor”属性的值设置为“grey”,如下所示:PushNotification.init({"android":{"senderId":"XX","icon":"ic_notif","iconColor":"grey"}});
使用此工具测试您的通知。
最近,PhoneGap Builder升级到了2版本(CLI v7.0.1),我现在可以使用cordova-plugin-push正确地显示白色通知图标。
我首先在GIMP中创建了带透明度的.png图标,然后将它们放在了我的项目中的/www/res/notify_icon/android/
目录下。
以下是我的config.xml文件的相关摘录:
<widget id="com.myapp.app" version="1.2.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
<preference name="phonegap-version" value="cli-7.0.1" />
<preference name="pgb-builder-version" value="2" />
...
<plugin name="phonegap-plugin-push" source="npm" spec="~2.0.0-rc5">
<param name="SENDER_ID" value="1xxxxxxxxxx0" />
</plugin>
...
<platform name="android">
<resource-file src="google-services.json" target="google-services.json" />
<resource-file src="www/res/notify_icon/android/notify_icon-36-ldpi.png" target="res/drawable-ldpi/notify_icon.png" />
<resource-file src="www/res/notify_icon/android/notify_icon-48-mdpi.png" target="res/drawable-mdpi/notify_icon.png" />
<resource-file src="www/res/notify_icon/android/notify_icon-72-hdpi.png" target="res/drawable-hdpi/notify_icon.png" />
<resource-file src="www/res/notify_icon/android/notify_icon-96-xhdpi.png" target="res/drawable-xhdpi/notify_icon.png" />
<resource-file src="www/res/notify_icon/android/notify_icon-144-xxhdpi.png" target="res/drawable-xxhdpi/notify_icon.png" />
<resource-file src="www/res/notify_icon/android/notify_icon-192-xxxhdpi.png" target="res/drawable-xxxhdpi/notify_icon.png" />
...
</platform>
</widget>
这是我初始化推送的地方:
document.addEventListener("deviceready", function() {
var push_options = {
android: {
senderID: "1xxxxxxxxxxx0",
sound: true,
vibrate: true,
icon: 'notify_icon',
iconColor: '#66CC00'
},
browser: {},
ios: {
senderID: "1xxxxxxxxxxx0",
alert: true,
badge: true,
sound: true
},
windows: {}
};
var push = PushNotification.init(push_options);
您只需要更改config.xml文件中的
android-targetSdkVersion
即可。
<preference name="android-targetSdkVersion" value="20" />
20 Android SDK版本支持Android中的标志。因此,您必须更改代码中的Android SDK版本。
对我来说,这个解决方案在结合这里的两个答案时有效:
首先,我设置了目标 SDK 版本
<preference name="android-targetSdkVersion" value="20"/>
然后我按照这里的建议编辑了插件代码,在 GCMIntentService 类中修改了 setNotificationSmallIcon 方法:
private void setNotificationSmallIcon(Context context, Bundle extras, String packageName, Resources resources, NotificationCompat.Builder mBuilder, String localIcon) {
mBuilder.setSmallIcon(getApplicationContext().getApplicationInfo().icon);
}
或者如果您想设置自定义图标,则使用
private void setNotificationSmallIcon(Context context, Bundle extras, String packageName, Resources resources, NotificationCompat.Builder mBuilder, String localIcon) {
mBuilder.setSmallIcon(<your.package.name>.R.drawable.<notification-drawable-name>);
}
在一段时间内,您可以将android-targetSdkVersion设置为API 20。此版本不使用破坏旧资源的新功能。
我也在这个问题上遇到了很多问题,但在整个互联网上搜索后,我找到了不同的解决方案。让我总结一下所有的解决方案并解释:
注意:此解决方案适用于Phonegap Cordova用户
<preference name="android-targetSdkVersion" value="20"/>
您需要将android-targetSdkVersion值设置为小于21。因此,在设置此值后,通知图标图像将出现在Android 6(Marshmallow)之前,它将无法在Android 7(Nougat)中工作。这个解决方案对我有用。
<preference name="StatusBarStyle" value="lightcontent" />
但是,此解决方案仅在打开应用程序时有效。因此,我认为这个解决方案不是最好的解决方案,但它适用于许多用户。
我相信以上其中一个解决方案将解决您的问题。
^
符号: 变量 notification 位置: 类 drawable您知道可能是什么原因吗? - shadowcursor