NotificationExtenderService not firing handleNotificationReceived
根据此处的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后绝对相关。
我从OneSignal收到一封邮件,指出版本3.6.2正在解决此问题。 所以Android的财产应该是com.onesignal:OneSignal:3.6.2现在。 查看我更新的文件更新问题。
你能说明你在离子项目中放置了哪些原生Java类吗? – thisdotvoid
对于Android部分,它位于platform-> android-> src-> com下。从那里你应该看到一个文件夹与您的项目名称和一个子文件夹为您的项目ID。简而言之,就是您的MainActivity.java所在的位置。不要忘记在AndroidManifest.xml中添加服务部分。 – Floydus