提交 5a45b7a9 authored 作者: shixiaochen's avatar shixiaochen

fix:修复更新悬浮窗方法崩溃问题;

上级 3dc45b7d
......@@ -244,43 +244,39 @@ public class WindowServiceNew extends Service implements View.OnTouchListener {
// update the notification
private void updateNotification(HashMap<String, Object> paramsMap) {
String notificationUpdateData = (String) paramsMap.get(Constants.KEY_UPDATE_NOTIFICATION_DATA);
assert notificationUpdateData != null;
HashMap<String, String> notificationData = new Gson().fromJson(notificationUpdateData, HashMap.class);
if (notificationData != null) {
LogUtils.getInstance().d(TAG, "Updating the notification");
LogUtils.getInstance().d(TAG, notificationData.toString());
String receiveAddress = notificationData.get(Constants.KEY_RECEIVE_ADDRESS);
String sendAddress = notificationData.get(Constants.KEY_SEND_ADDRESS);
String lastArriveSendTime = notificationData.get(Constants.KEY_LATEST_SEND_ADDRESS);
String lastArriveReceiveTime = notificationData.get(Constants.KEY_LATEST_RECEIVE_ADDRESS);
String lastLoadTime = notificationData.get(Constants.KEY_LATEST_LOAD_TIME);
if (receiveAddress != null) {
remoteViews.setTextViewText(R.id.tv_receive_address, receiveAddress);
}
if (sendAddress != null) {
remoteViews.setTextViewText(R.id.tv_send_address, sendAddress);
}
if (lastArriveSendTime != null) {
remoteViews.setTextViewText(R.id.tv_last_arrive_send_time, lastArriveSendTime);
}
if (lastArriveReceiveTime != null) {
remoteViews.setTextViewText(R.id.tv_last_arrive_receive_time, lastArriveReceiveTime);
}
if (lastLoadTime != null) {
remoteViews.setTextViewText(R.id.tv_last_load_time, "最晚装货:" + lastLoadTime);
}
notification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification_logo)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setCustomBigContentView(remoteViews)
.setContentIntent(pendingIntent)
.build();
if (Build.VERSION.SDK_INT >= 34) {
startForeground(NOTIFICATION_ID, notification, FOREGROUND_SERVICE_TYPE_SPECIAL_USE);
} else {
startForeground(NOTIFICATION_ID, notification);
}
if (notificationUpdateData != null) {
HashMap<String, String> notificationData = new Gson().fromJson(notificationUpdateData, HashMap.class);
if (notificationData != null) {
LogUtils.getInstance().d(TAG, "Updating the notification");
LogUtils.getInstance().d(TAG, notificationData.toString());
String receiveAddress = notificationData.get(Constants.KEY_RECEIVE_ADDRESS);
String sendAddress = notificationData.get(Constants.KEY_SEND_ADDRESS);
String lastArriveSendTime = notificationData.get(Constants.KEY_LATEST_SEND_ADDRESS);
String lastArriveReceiveTime = notificationData.get(Constants.KEY_LATEST_RECEIVE_ADDRESS);
String lastLoadTime = notificationData.get(Constants.KEY_LATEST_LOAD_TIME);
if (receiveAddress != null) {
remoteViews.setTextViewText(R.id.tv_receive_address, receiveAddress);
}
if (sendAddress != null) {
remoteViews.setTextViewText(R.id.tv_send_address, sendAddress);
}
if (lastArriveSendTime != null) {
remoteViews.setTextViewText(R.id.tv_last_arrive_send_time, lastArriveSendTime);
}
if (lastArriveReceiveTime != null) {
remoteViews.setTextViewText(R.id.tv_last_arrive_receive_time, lastArriveReceiveTime);
}
if (lastLoadTime != null) {
remoteViews.setTextViewText(R.id.tv_last_load_time, "最晚装货:" + lastLoadTime);
}
notification = new NotificationCompat.Builder(this, CHANNEL_ID).setSmallIcon(R.drawable.ic_notification_logo).setStyle(new NotificationCompat.DecoratedCustomViewStyle()).setCustomBigContentView(remoteViews).setContentIntent(pendingIntent).build();
if (Build.VERSION.SDK_INT >= 34) {
startForeground(NOTIFICATION_ID, notification, FOREGROUND_SERVICE_TYPE_SPECIAL_USE);
} else {
startForeground(NOTIFICATION_ID, notification);
}
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论