我有用于监听消息的客户端服务器套接字。
是否有一种方法可以从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());
}