Android Rongyun custom message interface size, Rongyun custom message notification bar display

Rongyun custom message notification bar display

The first step is to register a custom broadcast, the code is as follows:

public classCharNotificationReceiverextendsPushMessageReceiver {

@Override

public booleanonNotificationMessageArrived(Context context,PushNotificationMessage message) {

return false;//Return false, the default notification of Rongyun SDK will pop up; return true, Rongyun SDK will not display the notification, and the notification needs to be customized by you.

}

@Override

public booleanonNotificationMessageClicked(Context context,PushNotificationMessage message) {

return false;//Return false, it will follow the default processing logic of Rongyun SDK, that is, clicking the notification will open the session list or session interface; return true, you will customize the processing logic.

}

}

The second step is to register the broadcast you just created in your AndroidManifest.xml file

After the above two steps, you are half successful, but you still can't receive the notification of the message. This problem has puzzled me for a long time. Finally, I found that I did not set the monitoring of Rongyun to receive the message.

public class RongCloudEvent implements RongIMClient.OnReceiveMessageListener, RongIMClient.ConnectionStatusListener, RongIM.OnSendMessageListener {

private static RongCloudEvent mRongCloudInstance;

private final Context mContext;

//At the beginning, it was 2000 and changed to 1s

long time = 1000*60*30;

static SplashActivity act;

AHandler.Task task;

@Override

public boolean onReceived(Message message, int i) {

Log.d("",message.toString());

//如果接受到了消息就需要把定时任务关闭

task.cancel();

return false;

}

/**

* 初始化 RongCloud.

*

* @param context 上下文。

*/

public static void init(Context context) {

if (mRongCloudInstance == null) {

synchronized (RongCloudEvent.class) {

if (mRongCloudInstance == null) {

mRongCloudInstance = new RongCloudEvent(context);

}

}

}

}

/**

* 构造方法。

*

* @param context 上下文。

*/

private RongCloudEvent(Context context) {

mContext = context;

initDefaultListener();

}

/**

* 获取RongCloud 实例。

*

* @return RongCloud。

*/

public static RongCloudEvent getInstance() {

return mRongCloudInstance;

}

/**

* RongIM.init(this) 后直接可注册的Listener。

*/

private void initDefaultListener() {

RongIM.getInstance().setOnReceiveMessageListener(this);//设置消息接收监听器

RongIM.getInstance().setSendMessageListener(this);

RongIM.setConnectionStatusListener(this);

}

@Override

public void onChanged(ConnectionStatus connectionStatus) {

}

@Override

public Message onSend(Message message) {

Log.d("",message.toString());

AHandler.runTask(task = new AHandler.Task() {

@Override

public void update() {

//关闭咨询的接口请求

}

}, time);

return null;

}

@Override

public boolean onSent(Message message, RongIM.SentMessageErrorCode sentMessageErrorCode) {

Log.d("",message.toString());

return false;

}

}

第四步 要在你的application中初始化下RongCloudEvent这个类 ,这样的话就可以监听到融云发过来的消息了

//初始化融云 和融云消息的监听器

RongIM.init(this);

RongCloudEvent.init(this);

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324123448&siteId=291194637