如何将Message转换为CharSequence以在通知中显示来自套接字的消息?

时间:2019-04-10 11:30:11

标签: java android push-notification socketserver

我有用于监听消息的客户端服务器套接字。 是否有一种方法可以从Message msg obj获取内容并放入setNotificationMessage()以显示来自服务器的消息,如通知消息

我收到此错误

incompatible types: Message cannot be converted to CharSequence
            Message msg = new Message();
            Bundle bundle = new Bundle();
            bundle.putString(BUNDLE_DATA_KEY_VALUE, sb.toString());
            msg.setData(bundle);
            messageHandler.handleMessage(msg);
            setNotificationMessage(msg);
        }
    }


    private void setNotificationMessage(CharSequence message) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "1");
        builder.setSmallIcon(R.drawable.ic_launcher);
        builder.setContentTitle("Connection status");
        builder.setContentText(message);

        NotificationManagerCompat nm = NotificationManagerCompat.from(this);
        nm.notify(NOTIFICATION_ID, builder.build());
    }

0 个答案:

没有答案