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

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

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