package com.example.hdllinphonesdkdemo; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import android.text.TextUtils; import android.util.Log; import android.view.View; import android.widget.TextView; import android.widget.Toast; import com.hdl.hdllinphonesdk.HDLLinphoneKit; import com.hdl.hdllinphonesdk.activity.HDLLinphoneMonitorActivity; import com.hdl.hdllinphonesdk.callback.OnHDLLinphoneCallListener; import com.hdl.hdllinphonesdk.core.EasyLinphone; import com.hdl.hdllinphonesdk.core.service.HDLLinphoneService; import org.linphone.core.Address; import org.linphone.core.Call; import org.linphone.core.CallParams; import org.linphone.core.Core; import org.linphone.core.ProxyConfig; public class MainActivity extends Activity { private static final String TAG = "MainActivity"; private TextView mTextView,mTextView2,mTextView3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTextView = findViewById(R.id.tv_hello); mTextView2 = findViewById(R.id.mTextView2); mTextView3 = findViewById(R.id.mTextView3); mTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // startActivity(HDLLinphoneMonitorActivity.class); // EasyLinphone.callTo("0000",true); // EasyLinphone.setAccountAndLogin("44 EasyLinphone.setAccountAndLogin("4444", "85521566", "116.62.26.215:5060");44", "85521566", "116.62.26.215:5060"); // {"data": "{\"sipPassword\":\"8ec02ce0\",\"sipAccount\":\"61723164995710}} // {"data": "{\"sipPassword\":\"cc6d73c1\",\"sipAccount\":\"61723164995779}} // EasyLinphone.setAccountAndLogin("61723164995710", "8ec02ce0", "47.94.42.230:25060"); // HDLLinphoneKit.getInstance().setAccountAndLogin("61723164995710", "8ec02ce0", "sipproxy.ucpaas.com:25060"); // HDLLinphoneKit.getInstance().setAccountAndLogin("5555", "85521566", "116.62.26.215:5060"); HDLLinphoneKit.getInstance().setAccountAndLogin("5555", "85521566", "test-gz.hdlcontrol.com:5060"); } }); mTextView2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // HDLLinphoneKit.getInstance().callTo("61723164995779",true); // HDLcallTo("61723164995779",true); HDLcallTo("1427186301744910338",true); startActivity(HDLLinphoneMonitorActivity.class); } }); mTextView3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { logout(); } }); HDLLinphoneKit.getInstance().initLinphone(this); setOnHDLLinphoneCallListener(); } public void logout() { try { Core core = HDLLinphoneService.getCore(); ProxyConfig[] configs = core.getProxyConfigList(); for (ProxyConfig config : configs) { if (config != null) { config.edit(); config.enableRegister(false); config.done(); } } // core.clearAllAuthInfo(); // core.clearProxyConfig(); } catch (Exception e) { e.printStackTrace(); } } public Call HDLcallTo(String userName, boolean isVideoCall) { Call call = null; Core core = HDLLinphoneService.getCore(); Address addressToCall = core.interpretUrl(userName); CallParams params = core.createCallParams(null); if (isVideoCall) { params.enableVideo(true); params.enableLowBandwidth(false); } else { params.enableVideo(false); } if (addressToCall != null) { call = core.inviteAddressWithParams(addressToCall, params); } return call; } boolean openSuccess; void setOnHDLLinphoneCallListener(){ HDLLinphoneKit.getInstance().setOnHDLLinphoneCallListener( new OnHDLLinphoneCallListener() { @Override public void onAnswerAction() { showToast("接听"); // EasyLinphone.toggleMicro(true); } @Override public void onRejectCallAction() { showToast("拒接"); // EasyLinphone.hangUp(); } @Override public void onUnlockAction() { // showToast("开锁"); // EasyLinphone.callTo("61723164995779",true); openSuccess = !openSuccess; if(openSuccess){ HDLLinphoneKit.getInstance().onOpenSuccess(); }else{ HDLLinphoneKit.getInstance().onOpenError("设备不在线"); } } @Override public void onHangUpAction(int callDuration) { showToast("挂断 通话时长:"+callDuration); // EasyLinphone.hangUp(); } @Override public void onScreenshotSuccessfulAction(Bitmap image) { showToast("截图"); } }); } /** * showToast */ private void showToast(String text) { Toast.makeText(this, text, Toast.LENGTH_SHORT).show(); } public void startActivity(Class clazz) { Intent intent = new Intent(this, clazz); startActivity(intent); } }