Android Sinch 服务不支持 CallId 中的特殊字符
Android Sinch service not supported special characters in CallId
我正在使用 sinch 调用服务进行应用程序调用,只要我在 onSinchServiceConnected() 中使用 int 和字符串作为 callId,它就可以正常工作但是如果用户名有特殊字符,则不会进行调用。
AppConstant.CALL_ID = mCallId = getIntent().getStringExtra(
SinchService.CALL_ID);//Contain Special characters.
//And in onServiceConnected() use
Call call = getSinchServiceInterface().getCall(mCallId);
作为一般准则,使用 Sinch 呼叫时,应根据 E.164 号码格式 ([http://en.wikipedia.org/wiki/E.164][1]
) 建议指定 phone 号码,并应以“+”为前缀。
我不能完美地回答你的问题,但我认为可以这样解决。
您可以使用 mCallId 的编码和解码来完成此操作。
在放置呼叫时编码 callId
public String Encode(String str) {
byte[] data = null;
try {
data = str.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String base64 = Base64.encodeToString(data, Base64.DEFAULT);
return base64;
}
并使用呼叫 ID 作为
Call call = getSinchServiceInterface().callUser(Encode(name));
接听电话
public String decode(String str) {
byte[] data = Base64.decode(str, Base64.DEFAULT);
String text = null;
try {
text = new String(data, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return text;
}
并使用它
String userEncoded = call.getRemoteUserId();
String decodedUserName = decode(userEncoded);
我正在使用 sinch 调用服务进行应用程序调用,只要我在 onSinchServiceConnected() 中使用 int 和字符串作为 callId,它就可以正常工作但是如果用户名有特殊字符,则不会进行调用。
AppConstant.CALL_ID = mCallId = getIntent().getStringExtra(
SinchService.CALL_ID);//Contain Special characters.
//And in onServiceConnected() use
Call call = getSinchServiceInterface().getCall(mCallId);
作为一般准则,使用 Sinch 呼叫时,应根据 E.164 号码格式 ([http://en.wikipedia.org/wiki/E.164][1]
) 建议指定 phone 号码,并应以“+”为前缀。
我不能完美地回答你的问题,但我认为可以这样解决。 您可以使用 mCallId 的编码和解码来完成此操作。 在放置呼叫时编码 callId
public String Encode(String str) {
byte[] data = null;
try {
data = str.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String base64 = Base64.encodeToString(data, Base64.DEFAULT);
return base64;
}
并使用呼叫 ID 作为
Call call = getSinchServiceInterface().callUser(Encode(name));
接听电话
public String decode(String str) {
byte[] data = Base64.decode(str, Base64.DEFAULT);
String text = null;
try {
text = new String(data, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return text;
}
并使用它
String userEncoded = call.getRemoteUserId();
String decodedUserName = decode(userEncoded);