根據此處的OneSignal文檔One signal doc,我正在擴展NotificationExtenderService
Java類中,但是我意識到返回true會阻止顯示通知。完美到目前爲止,問題是我仍然需要在我的腳本代碼中觸發handleNotificationReceived
。NotificationExtenderService not firing handleNotificationReceived
這裏的Java代碼擴展如下:
public class NotificationExtenderBareBonesExample extends NotificationExtenderService {
@Override
protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
receivedResult.payload.lockScreenVisibility = Integer.parseInt("-1");
JSONObject data = receivedResult.payload.additionalData;
OverrideSettings overrideSettings = new OverrideSettings();
overrideSettings.extender = new NotificationCompat.Extender() {
@Override
public NotificationCompat.Builder extend(NotificationCompat.Builder builder) {
// Sets the background notification color to Green on Android 5.0+ devices.
builder = builder.setVisibility(Integer.parseInt("-1"));
builder = builder.setVibrate(new long[]{0L});
return builder.setColor(new BigInteger("800d2f66", 16).intValue());
}
};
OSNotificationDisplayedResult displayedResult = displayNotification(overrideSettings);
Log.d("OneSignalExample", "Notification displayed with id: " + displayedResult.androidNotificationId);
return true;
}
}
我遇到的問題是,我需要調用displayNotification
爲有我NotificationReceivedHandler
觸發(分析了additionalData和運行部分相應) 。
離子2代碼:
this.oneSignal.handleNotificationReceived().subscribe((result) => {
alert('received ' + JSON.stringify(result));
thisRef.writeDebug('notification received');
let data = result.payload.additionalData;
let chatmessage = "";
if (data != null) {
if(typeof data !== 'undefined' && data.length != 0)
{
if(typeof data.chatmessage !== 'undefined')
console.log('chatmessage ok');
if(typeof data.id !== 'undefined')
thisRef._callbackOnChatMessage({chatmessage: data.chatmessage, id: data.id.toString()})
if(typeof data.shortgeolocation !== 'undefined')
{
this._callbackRequestShortLocation(data.shortgeolocation);
}
}
if(typeof data.othertyping !== 'undefined' && typeof thisRef._callbackOnOtherTyping !== 'undefined')
{
thisRef._callbackOnOtherTyping(data.othertyping);
}
}
});
這是我通知的預覽一旦它到達了我的離子處理程序:
有什麼辦法來改變displayType
和Shown
值從NotificationExtenderService
分別爲0和false,以便在Ionic中調用NotificationReceivedHandler並且不顯示警報? (我有這種行爲在iOS下工作,努力在Android中做同樣的事情)。
解決,部分地,我只好onesignal庫降級到3.5.6 在平臺/ android.properties,使用cordova.system.library [保留您的號碼X] = com.onesignal:OneSignal:3.5.6 修復了這個問題。 對於離子,該文件是在平臺/安卓/
見this後絕對相關。
你能說明你在離子項目中放置了哪些原生Java類嗎? – thisdotvoid
對於Android部分,它位於platform-> android-> src-> com下。從那裏你應該看到一個文件夾與您的項目名稱和一個子文件夾爲您的項目ID。簡而言之,就是您的MainActivity.java所在的位置。不要忘記在AndroidManifest.xml中添加服務部分。 – Floydus