我搞亂Phonegap使用Adobe的生成服務,我想知道如果(如果是這樣,如何)我可以使我的通知顯示一個白色的圖標(如谷歌描述here )。我正在使用PushPlugin,但我找不到任何文檔。目前我的應用只在通知內容旁邊顯示啓動器圖標。與Phonegap生成和PushPlugin Android的白色通知圖標
因此,沒有人知道是否有一些方法來啓用替代通知圖標與PushPlugin,我堅持啓動圖標還是有另一個插件與此功能?
謝謝!
我搞亂Phonegap使用Adobe的生成服務,我想知道如果(如果是這樣,如何)我可以使我的通知顯示一個白色的圖標(如谷歌描述here )。我正在使用PushPlugin,但我找不到任何文檔。目前我的應用只在通知內容旁邊顯示啓動器圖標。與Phonegap生成和PushPlugin Android的白色通知圖標
因此,沒有人知道是否有一些方法來啓用替代通知圖標與PushPlugin,我堅持啓動圖標還是有另一個插件與此功能?
謝謝!
新的「phonegap-plugin-push」插件有新棒棒糖通知圖標很好的支持。
構建一個首先在透明圖標上有顏色的圖標。根據谷歌的guidelines,所有通知將在通知欄中顯示爲白色。
因此,建立圖標,然後指定它如下。 「圖標」指定圖像。 「myicon」 在合適的分辨率/平臺/安卓/ RES /繪製-RES /文件夾的
地方拷貝如下:
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
現在在你的JS,指定您的圖標。 「iconColor」是可選的,當您向下滑動時將指定背景。
var push = PushNotification.init({
"android": {
"senderID": "<<SENDER_ID>>",
"icon": "myicon",
"iconColor": "#123456"
},
在您的推送負載中,您現在可以覆蓋通過添加「圖像」參數向下滑動指定的圖標。圖片既可以是資源,也可以引用「www/image/image.png」,也可以是完整的網址。
「plugin docs」非常好,我推薦閱讀。希望這對某個人有用。
我從來沒有使用Phonegap構建 - 我在我的機器上手動執行構建過程。無論如何,我認爲你應該在src/com/plugin/gcm下找到GCMIntentService.java文件。在該文件中,搜索以下代碼行:
.setSmallIcon(context.getApplicationInfo().icon)
這可能會被您想要的圖標替換。如果您放置在/ RES /繪製的文件夾命名爲圖標「notification.png」,你可以改變的代碼行:
.setSmallIcon(your.package.name.R.drawable.notification);
如果您使用Build'sPushPlugin;本地修改爲.setSmallIcon()
#100將會丟失。
除非你在當地建造或使用替代GCM插件,你僅限於修改:
title extras.getString("title")
message extras.getString("message")
msgcnt extras.getString("msgcnt")
一時間,你可以在Android targetSdkVersion設置爲API 20 這個版本不使用新功能,打破了舊資源。
這工作..但玩商店不會讓你用降級API更新應用程序.. – Lakshay
設置這對您的PhoneGap或科爾多瓦config.xml中
<preference name="android-targetSdkVersion" value="20"/>
好!已解決我的案例 –
這是一個非常冒險的解決方案,並不是很有前途的證據。它現在可以工作,但是明確地將Lollipop從你的版本中排除。 –
我試過了,它也適用於我 – VyTcdc
這是新的插件 - phonegap-plugin-push
可能會爲老PushPlugin正常工作。
Android爲棒棒糖及以上版本的通知圖標設置了指南。該圖標需要純白色和透明。
我做了什麼:
生成不同大小的我的標誌圖像(允許其命名爲「notif.png」)中具有透明的背,用這種tool。記得有一個透明的背影,如果你沒有透明的圖像,android只會顯示白色圖標。讓我們假設生成的圖標的名稱是「ic_notif」。
將各自尺寸的圖像複製到res/drawables文件夾中。
在推送JS代碼中,將值「ic_notif」賦予「icon」屬性。而 「灰」 到 「iconColor通過」 屬性是這樣的:PushNotification.init({"android":{"senderId":"XX","icon":"ic_notif","iconColor":"grey"}});
使用此tool您的通知測試。
首先,我設定的目標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 API 21+只使用白色爲小圖標。 更改目標SDK版本會讓您的編譯器使用更老版本的SDK,因此您將可以使用新的SDK功能。 所以最好的方法是有兩個圖標:小和大(當酒吧被拖下去)
我也面臨太多的問題,但在搜索整個互聯網後,我發現這個問題的不同解決方案。讓我總結了所有的解決方案,並解釋:
注意:此方法是PhoneGap的科爾多瓦用戶
<preference name="android-targetSdkVersion" value="20"/>
您需要將您的android-targetSdkVersion值設置爲小於21. 因此設置此值後,通知圖標圖片將顯示至Android 6(Marshmallow),它不會在Android 7(Nougat)中運行。 該解決方案適用於我。
<preference name="StatusBarStyle" value="lightcontent" />
但您的應用程序打開時,此解決方案纔有效。 所以,我想這個解決方案不是最好的解決方案,但它對很多用戶都有效。
而且我相信上述解決方案的一個會爲你的問題開展工作。
隨着最近更新的PhoneGap構建器版本2(和CLI V7.0.1),我現在能夠得到白色的通知圖標與科爾多瓦 - 插件推正確顯示。
我第一次在GIMP創建了巴紐圖標(透明度)。然後我把它們放在我的項目在/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" />
的Android SDK版本支持Android的標誌。所以你必須在代碼中更改android sdk版本。
將在什麼地方/ RES /繪製的文件夾呢? –
當你的建議,我得到了修改建設這個 平臺/安卓/ src目錄/ COM /插件/ GCM/GCMIntentService.java:105:錯誤:無法找到符號 \t \t \t \t .setSmallIcon(R.drawable .notification) \t \t \t \t ^ 符號:變量通知 位置:類繪製 你就會知道爲什麼,可能是? –