Search code examples
androidsinch

Android Sinch service not supported special characters in CallId


I am using sinch calling service for app to app call it works fine whenever i use int and string as callId in onSinchServiceConnected() But if user name has special characters then call is not placed.

AppConstant.CALL_ID = mCallId = getIntent().getStringExtra(
            SinchService.CALL_ID);//Contain Special characters.

//And in onServiceConnected() use

    Call call = getSinchServiceInterface().getCall(mCallId);

Solution

  • I cant get your question perfectly but i think that is solved like this. You can done this by using encode and decode of mCallId. while placeing call encode 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;
    }
    

    and Use call id as

    Call call = getSinchServiceInterface().callUser(Encode(name));
    

    and on Receive call

    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;
    }
    

    and use it

    String userEncoded = call.getRemoteUserId();
    String decodedUserName = decode(userEncoded);