我使用OneSignal Android SDK从服务器接收通知,并且工作正常,但是当解析时,与通知消息正文无关的内容不正确时,它将崩溃。
主要问题是:发现的崩溃不在应用程序代码中,崩溃发生在OneSignal SDK Lib中。
任何人都可以帮助解决该问题吗?
谢谢。
我尝试检查以下条件:如果未收到正确的密钥集,并且没有去检查通知,
还选中if(notification.payload.toJSONObject().has("additionalData"))
@Override
protected boolean onNotificationProcessing(OSNotificationReceivedResult
notification) {
int notificationId = 1;
String CHANNEL_ID = "VIDEO_ID";
try {
JSONObject json = notification.payload.toJSONObject();
Log.e("json : ", json.toString());
if (json.has("additionalData")) {
String title = notification.payload.title;
String body = notification.payload.body;
JSONObject objTag = json.getJSONObject("additionalData");
Intent intentReceiver;
if (objTag.has("content_id")) {
String videoId = objTag.getString("content_id");
String vidName = "";
intentReceiver = new Intent(getApplicationContext(),
VideoDetailsActivity.class);
intentReceiver.putExtra(VideoDetailsActivity.EXTRA_VIDEO_ID,
videoId);
intentReceiver.putExtra(VideoDetailsActivity.EXTRA_VIDEO_NAME, vidName);
intentReceiver.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pIntent =
PendingIntent.getActivity(getApplicationContext(), (int)
System.currentTimeMillis(), intentReceiver, 0);
Uri uriSound =
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mBuilder;
NotificationManager mNotifyManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
Bitmap bmp = null;
try {
InputStream in = new
URL(objTag.optString("thumb")).openStream();
bmp = BitmapFactory.decodeStream(in);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (android.os.Build.VERSION.SDK_INT >=
android.os.Build.VERSION_CODES.O) {
NotificationChannel channel = new
NotificationChannel(CHANNEL_ID, "tag",
NotificationManager.IMPORTANCE_HIGH);
channel.setDescription("Tag Search");
channel.enableVibration(true);
channel.setSound(uriSound, new
AudioAttributes.Builder().build());
mNotifyManager.createNotificationChannel(channel);
}
mBuilder = new
NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID);
mBuilder.setContentTitle(title)
.setContentText(body)
.setPriority(Notification.PRIORITY_HIGH)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),
R.mipmap.ic_launcher))
.setSmallIcon(R.drawable.noti_icon_small)
.setSound(uriSound)
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setContentIntent(pIntent);
if (bmp != null) {
NotificationCompat.BigPictureStyle style = new
NotificationCompat.BigPictureStyle()
.bigPicture(bmp);
mBuilder.setStyle(style);
}
mNotifyManager.notify(notificationId, mBuilder.build());
}
}
notification.restoring = true;
return true;
}
} catch (JSONException e) {
e.printStackTrace();
notification.restoring = true;
return true;
}
OverrideSettings overrideSettings = new OverrideSettings();
overrideSettings.extender = new NotificationCompat.Extender() {
@Override
public NotificationCompat.Builder extend(NotificationCompat.Builder
builder) {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.mipmap.ic_launcher);
int color = ContextCompat.getColor(getApplicationContext(),
R.color.colorPrimary);
builder.setColor(color)
.setSmallIcon(R.drawable.noti_icon_small)
.setLargeIcon(bitmap);
return builder;
}
};
String body = notification.payload.body;
OSNotificationDisplayedResult displayedResult =
displayNotification(overrideSettings);
return false;
}
错误:
java.lang.RuntimeException:
at android.app.ActivityThread.handleReceiver (ActivityThread.java:3413)
at android.app.ActivityThread.-wrap18 (Unknown Source)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1807)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:7000)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1408)
Caused by: java.lang.IllegalArgumentException:
at android.os.Parcel.readException (Parcel.java:2025)
at android.os.Parcel.readException (Parcel.java:1967)
at android.app.job.IJobScheduler$Stub$Proxy.enqueue (IJobScheduler.java:211)
at android.app.JobSchedulerImpl.enqueue (JobSchedulerImpl.java:53)
at com.onesignal.JobIntentService$JobWorkEnqueuer.enqueueWork (JobIntentService.java:9)
at com.onesignal.JobIntentService.enqueueWork (JobIntentService.java:21)
at com.onesignal.NotificationBundleProcessor.startExtenderService (NotificationBundleProcessor.java:47)
at com.onesignal.NotificationBundleProcessor.a (NotificationBundleProcessor.java:18)
at com.onesignal.GcmBroadcastReceiver.processOrderBroadcast (GcmBroadcastReceiver.java:8)
at com.onesignal.GcmBroadcastReceiver.onReceive (GcmBroadcastReceiver.java:22)
at android.app.ActivityThread.handleReceiver (ActivityThread.java:3406)
at android.app.ActivityThread.-wrap18 (Unknown Source)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1807)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:7000)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1408)