点击接收到的消息,会出现 Key platform expected String but value was a java.lang.Byte. The default value <null> was returned.
使用到了极光推送的Flutter 插件
插件的版本是0.0.8
main.dart中的代码
//String debugLable = 'Unknown';
final JPush jpush = new JPush();
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
jpush.getRegistrationID().then((rid) {
print("极光推送,此设备rID为:$rid");
setState(() {
//debugLable = "flutter getRegistrationID: $rid";
print("极光推送,此设备rID为:$rid");
});
});
jpush.setup(
appKey: "fc3571b8c7bfa557bd078fc6",
channel: "theChannel",
production: false,
debug: true,
);
jpush.applyPushAuthority(new NotificationSettingsIOS(
sound: false,
alert: false,
badge: false));
try {
jpush.addEventHandler(
// 接收通知回调方法。
onReceiveNotification: (Map<String, dynamic> message) async {
print("接受到极光推送通知 onReceiveNotification: $message");
// setState(() {
// _platformVersion = "flutter onReceiveNotification: $message";
// });
},
// 点击通知回调方法。
onOpenNotification: (Map<String, dynamic> message) async {
print("极光推送点击回调 onOpenNotification: $message");
NavigatorUtils.gotoWebViewPage(context, "http://www.baidu.com", "通知跳转测试");
setState(() {
//debugLable = "flutter onOpenNotification: $message";
});
},
// 接收自定义消息回调方法。
onReceiveMessage: (Map<String, dynamic> message) async {
print("极光推送自定义消息推送 onReceiveMessage: $message");
},
);
} on PlatformException {
platformVersion = 'Failed to get platform version.';
print("PlatformException:"+ platformVersion);
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
//debugLable = platformVersion;
});
}
在发送测试消息的时候,点击接收到的消息,会出现以下的exception:
Key platform expected String but value was a java.lang.Byte. The default value was returned.
D/JIGUANG-JCore(10220): [PushReceiver] onReceive - cn.jpush.android.intent.NOTIFICATION_OPENED_PROXY.2d823e2a-c603-403f-b155-57b393e80f50
D/JIGUANG-JPush(10220): [PushReceiverCore] onReceive - cn.jpush.android.intent.NOTIFICATION_OPENED_PROXY.2d823e2a-c603-403f-b155-57b393e80f50
D/ViewRootImpl@725cd5f[MainActivity](10220): MSG_WINDOW_FOCUS_CHANGED 1
D/JIGUANG-JPush(10220): [PushReceiverCore] Send broadcast to app: com.example.dfelectricapp action=cn.jpush.android.intent.NOTIFICATION_OPENED
W/Bundle (10220): Key platform expected String but value was a java.lang.Byte. The default value <null> was returned.
W/Bundle (10220): Attempt to cast generated internal exception:
W/Bundle (10220): java.lang.ClassCastException: java.lang.Byte cannot be cast to java.lang.String
W/Bundle (10220): at android.os.BaseBundle.getString(BaseBundle.java:1089)
W/Bundle (10220): at android.content.Intent.getStringExtra(Intent.java:7706)
W/Bundle (10220): at com.jiguang.jpush.JPushPlugin$JPushReceiver.getNotificationExtras(JPushPlugin.java:300)
W/Bundle (10220): at com.jiguang.jpush.JPushPlugin$JPushReceiver.handlingNotificationOpen(JPushPlugin.java:275)
W/Bundle (10220): at com.jiguang.jpush.JPushPlugin$JPushReceiver.onReceive(JPushPlugin.java:262)
W/Bundle (10220): at android.app.ActivityThread.handleReceiver(ActivityThread.java:3392)
W/Bundle (10220): at android.app.ActivityThread.-wrap18(Unknown Source:0)
W/Bundle (10220): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1780)
W/Bundle (10220): at android.os.Handler.dispatchMessage(Handler.java:105)
W/Bundle (10220): at android.os.Looper.loop(Looper.java:164)
W/Bundle (10220): at android.app.ActivityThread.main(ActivityThread.java:6944)
W/Bundle (10220): at java.lang.reflect.Method.invoke(Native Method)
W/Bundle (10220): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
W/Bundle (10220): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
D/JPushPlugin(10220): instance.dartIsReady is true
I/flutter (10220): 极光推送点击回调 onOpenNotification: {alert: 的发射点发, extras: {app: com.example.dfelectricapp, cn.jpush.android.ALERT_TYPE: 7, cn.jpush.android.NOTIFICATION_ID: 189334024, cn.jpush.android.MSG_ID: 3377710911, cn.jpush.android.NOTIFICATION_TYPE: 0, cn.jpush.android.ALERT: 的发射点发, platform: null, cn.jpush.android.EXTRA: {}, sdktype: JPUSH}, title: df_electric_app}
W/Activity(10220): AppLock checkAppLockState locked:false verifying:false pkgName = com.example.dfelectricapp isInMultiWindowMode:false showWhenLocked:false
I/System.out(10220): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out(10220): (HTTPLog)-Static: isSBSettingEnabled false
D/JIGUANG-JCore(10220): [HttpHelper] status code:200 retry left:2
虽然报这个异常,但是正常的接收消息回调和点击消息回调是正常的,请问下这个错误是什么原因以及如何修正。
谢谢。
版本是:0.0.8
flutter doctor:
```
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.11.7, on Microsoft Windows [Version 10.0.17134.472], locale zh-CN)
[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
[√] Android Studio (version 3.2)
[√] Connected device (1 available)
• No issues found!