Currently, IM uses the vendor JAR package provided by TPNS. You can solve this problem by referring to the IM Offline Push (Android) documentation and replacing relevant dependency packages.
Whether it’s a C2C message or a group message, if the problem cannot be confirmed through the above steps, you need to continue to confirm the following issues:
elem
to the message when sending the message (check the return value of addElement
when sending a message).true
was returned in the message listeners.APNs
Refer to the offline push (iOS) documentation and confirm the following issues:
TIMCustomElem
, with the desc
attribute being left empty.MsgRandom
were set to the same value, resulting in push failures due to deduplication.Android
Refer to the offline push documentation and confirm the following issues:
When using either APNs push or Android offline push, if the problem cannot be located through the above steps, you need to continue on to confirm the following issues:
sendOnlineMessage
API or that MsgLifeTime
was set to 0
during push through a RESTful API.There is no essential difference between an in-group @ message and an ordinary message, although the user specified by @ will see a special UI effect. For example, the message will be highlighted in red on the QQ message list. For the specific implementation, you can refer to the following scheme:
TIMCustomElem
in the message, and in the TIMCustomElem
, add a custom message protocol to mark the message as an @ message.{
"type":"REMIND",
"target":"user1"
}
The sample code for constructing an @ message is as follows (here, the Android platform is used as an example):// Send a text message and specify user1 as the @ target
TIMMessage msg = new TIMMessage();
// Construct the text message elements
TIMTextElem txtElem = new TIMTextElem();
txtElem.setText("@user1 nice to meet u");
if(msg.addElement(txtElem) != 0){
Log.e(TAG, "add text elem failed");
return;
}
try{
// Specify the custom message protocol
JSONObject remindProto = new JSONObject();
remindProto.put("type", "REMIND");
remindProto.put("target", "user1");
// Construct custom message elements based on the custom protocol
TIMCustomElem customElem = new TIMCustomElem();
customElem.setDesc("remind msg");
customElem.setData(remindProto.toString().getBytes("utf-8"));
if(msg.addElement(customElem) != 0){
Log.e(TAG, "add custom elem failed");
return;
}
}catch(Exception e){
Log.e(TAG, "build custom elem failed");
return;
}
Note:
In the configuration,
TIMTextElem
is not required. If you are sure that foul language filtering is not needed, you can fill the message content ofTIMTextElem
to thedesc
attribute inTIMCustomElem
.
TIMCustomElem
is the @ message protocol. If yes, go to the next step. Otherwise, skip it.Red packet messages are similar to @ messages and can be implemented via TIMCustomElem
. Red packet messages require apps to perform special processing on the UI. For example, if the system detects that the current message is a red packet message, the message should be displayed in the form of a red packet.
In addition, as red packet messages are important messages, we recommend that you set the message priority to high when sending a red packet message. As far as possible, this ensures that the red packet message will reach the target user even if the message frequency limit is reached (currently, the default frequency limit for in-group messages is 40 messages per second, and that for one-to-one chat messages is 5 messages per second).
For more information about message priority, see Message Priority.
Note:
The payment feature of red packet messages requires manual integration of the corresponding payment SDK. At present, the IM SDK does not provide this payment feature.
The process for constructing a simple red packet message is as follows (Android):
// Construct a new message
TIMMessage msg = new TIMMessage();
try{
// Specify the custom message protocol
JSONObject redPacket= new JSONObject();
redPacket.put("type", "RED_PACKET");
redPacket.put("amount", 2018);
redPacket.put("msg", "Happy new year!");
// Construct custom message elements based on the custom protocol
TIMCustomElem customElem = new TIMCustomElem();
customElem.setDesc("red packet");
customElem.setData(redPacket.toString().getBytes("utf-8");
if(msg.addElement(customElem) != 0){
Log.e(TAG, "add custom elem failed");
return;
}
}catch(Exception e){
Log.e(TAG, "build custom elem failed");
return;
}
// Set the message priority to high
msg.setPriority(TIMMessagePriority.High);
Historical message storage is available for one-to-one chat messages and non–audio-video group messages. You can log in to the IM console to modify the relevant configuration. The default configuration for different packages is as follows:
Was this page helpful?