Skip to content

Commit

Permalink
set push custom ringtone for huawei and apple.
Browse files Browse the repository at this point in the history
  • Loading branch information
jinanzhuan committed Aug 21, 2020
1 parent 5d6966a commit 5bbc0f5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/src/main/java/com/hyphenate/chatuidemo/ui/CallActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,19 @@ public void onRemoteOffline(final String to) {

final EMMessage message = EMMessage.createTxtSendMessage("You have an incoming call", to);
// set the user-defined extension field
// 设置ios端铃声文件及开启apns通知扩展
JSONObject apns = new JSONObject();
try {
apns.put("em_push_sound", "ring.caf");
apns.put("em_push_name", CallActivity.this.getString(R.string.incoming_call));
apns.put("em_push_content", CallActivity.this.getString(R.string.incoming_call));
//保证 APNs 通知扩展
apns.put("em_push_mutable_content", true);
} catch (JSONException e) {
e.printStackTrace();
}
message.setAttribute("em_apns_ext", apns);

//设置呼叫类型
message.setAttribute("is_voice_call", callType == 0 ? true : false);

JSONObject extObject = new JSONObject();
Expand All @@ -110,14 +115,19 @@ public void onRemoteOffline(final String to) {
}
message.setAttribute("em_push_ext", extObject);


//设置自定义铃声,"/raw/ring"为应用"/res/raw/**",ring为铃声文件名(不包含后缀)
//若需更换铃声,请将铃声拷贝到"/res/raw/"目录下,并将下面的"ring"更换成相应的文件名即可
JSONObject sound = new JSONObject();
try {
sound.put("em_push_name", CallActivity.this.getString(R.string.incoming_call));
sound.put("em_push_content", CallActivity.this.getString(R.string.incoming_call));
sound.put("em_push_sound", "/raw/ring");
} catch (JSONException e) {
e.printStackTrace();
}
message.setAttribute("em_android_push_ext", sound);
//强制推送,忽略消息免打扰设置
message.setAttribute("em_force_notification", true);
message.setMessageStatusCallback(new EMCallBack(){

@Override
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh/em_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@
<string name="group_nick">聊天室名称:</string>
<string name="group_owner">群主:</string>
<string name="user_removed_from_group">你已经被移除群</string>
<string name="incoming_call">您有新的通话消息</string>

<string name="register_exceed_service_limit">您的App用户注册数量已达上限,请升级至企业版</string>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/em_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@
<string name="group_nick">Group Nickname:</string>
<string name="group_owner">Group Owner:</string>
<string name="user_removed_from_group">You are removed from the group</string>
<string name="incoming_call">You have an incoming call</string>

<string name="register_exceed_service_limit">You have exceeded the limit of the community edition,Please upgrade to the enterprise edition</string>

Expand Down

0 comments on commit 5bbc0f5

Please sign in to comment.