| | |
| | | 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.HDLLinphoneIntercomActivity; |
| | | 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 com.hdl.hdllinphonesdk.utils.HDLLog; |
| | | |
| | | 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; |
| | | private TextView mTextView,mTextView2,mTextView3,mTextView4; |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | |
| | | mTextView = findViewById(R.id.tv_hello); |
| | | mTextView2 = findViewById(R.id.mTextView2); |
| | | mTextView3 = findViewById(R.id.mTextView3); |
| | | |
| | | mTextView4 = findViewById(R.id.mTextView4); |
| | | |
| | | mTextView.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | |
| | | // 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"); |
| | | // HDLLinphoneKit.getInstance().setAccountAndLogin("5555", "85521566", "test-gz.hdlcontrol.com:5060"); |
| | | // HDLLinphoneKit.getInstance().setAccountAndLogin("6666", "85521566", "test-gz.hdlcontrol.com:5060"); |
| | | |
| | | HDLLinphoneKit.getInstance().setAccountAndLogin("7777", "85521566", "test-gz.hdlcontrol.com:35060"); |
| | | |
| | | |
| | | |
| | | |
| | | // |
| | | // HDLLinphoneKit.getInstance().setAccountAndLogin("8888", "85521566", "test-gz.hdlcontrol.com:5060"); |
| | | // |
| | | // HDLLinphoneKit.getInstance().setAccountAndLogin("4444", "85521566", "test-gz.hdlcontrol.com:5060"); |
| | | |
| | | |
| | | } |
| | | }); |
| | | |
| | | mTextView4.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | clearProxyConfig(); |
| | | HDLLinphoneKit.getInstance().setAccountAndLogin("5555", "85521566", "test-gz.hdlcontrol.com:35060"); |
| | | } |
| | | }); |
| | | |
| | | mTextView2.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | |
| | | // logoutLog(); |
| | | // return; |
| | | // HDLLinphoneKit.getInstance().callTo("61723164995779",true); |
| | | // HDLcallTo("61723164995779",true); |
| | | HDLcallTo("1427186301744910338",true); |
| | | HDLLinphoneKit.getInstance().callTo("1427186301744910338",true); |
| | | startActivity(HDLLinphoneMonitorActivity.class); |
| | | |
| | | |
| | | } |
| | | }); |
| | | |
| | | mTextView3.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | logout(); |
| | | HDLLinphoneKit.getInstance().getCore().enableVideoCapture(false);//禁用手机摄像头视频采集 |
| | | // //1.启用PCMA 8000 |
| | | // PayloadType[] ptList = HDLLinphoneKit.getInstance().getCore().getAudioPayloadTypes(); |
| | | // for (PayloadType pt : ptList) { |
| | | //// HDLLog.i("payloadaudio", pt.getMimeType()); |
| | | // if ((pt.getMimeType().equals("PCMA") || pt.getMimeType().equals("PCMU")) && pt.getClockRate() == 8000) { |
| | | //// pt.enable(true); |
| | | // HDLLog.i("payloadaudio true", pt.getMimeType() + ": "+ pt.getClockRate()+"HZ " + pt.enabled()); |
| | | // } else { |
| | | //// pt.enable(false); |
| | | // HDLLog.i("payloadaudio false", pt.getMimeType() + ": "+ pt.getClockRate()+"HZ "+ pt.enabled()); |
| | | // } |
| | | // } |
| | | // logout(); |
| | | } |
| | | }); |
| | | |
| | | HDLLinphoneKit.getInstance().initLinphone(this); |
| | | HDLLinphoneKit.getInstance().setAutoJumpCallView(true); |
| | | setOnHDLLinphoneCallListener(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 退出清空账号 |
| | | * enableRegister false |
| | | */ |
| | | 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(); |
| | | if (core != null) { |
| | | ProxyConfig[] configs = core.getProxyConfigList(); |
| | | for (ProxyConfig config : configs) { |
| | | if (config != null) { |
| | | config.edit(); |
| | | config.enableRegister(false); |
| | | config.done(); |
| | | } |
| | | } |
| | | // core.clearAllAuthInfo();//清除所有认证信息。 |
| | | // core.clearProxyConfig();//从配置中删除所有代理。 |
| | | } |
| | | // core.clearAllAuthInfo(); |
| | | // core.clearProxyConfig(); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public Call HDLcallTo(String userName, boolean isVideoCall) { |
| | | Call call = null; |
| | | public void clearProxyConfig() { |
| | | 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 (core != null) { |
| | | core.setDefaultProxyConfig(null); |
| | | core.clearAllAuthInfo(); |
| | | core.clearProxyConfig(); |
| | | // core.refreshRegisters();//强制在下一次迭代时启动注册刷新 |
| | | // core.ensureRegistered(); |
| | | } |
| | | |
| | | if (addressToCall != null) { |
| | | call = core.inviteAddressWithParams(addressToCall, params); |
| | | } |
| | | |
| | | return call; |
| | | } |
| | | |
| | | public void logoutLog() { |
| | | try { |
| | | Core core = HDLLinphoneService.getCore(); |
| | | ProxyConfig[] configs = core.getProxyConfigList(); |
| | | if(configs != null) { |
| | | HDLLog.E("registrationState账户length" + configs.length); |
| | | } |
| | | |
| | | for (ProxyConfig config : configs) { |
| | | HDLLog.E("registrationState账户"+config.getIdentityAddress().getUsername()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | boolean openSuccess; |
| | | void setOnHDLLinphoneCallListener(){ |
| | |
| | | |
| | | @Override |
| | | public void onUnlockAction() { |
| | | // |
| | | HDLLinphoneKit.getInstance().getCore().enableVideoCapture(true);//禁用手机摄像头视频采集 |
| | | |
| | | // showToast("开锁"); |
| | | // EasyLinphone.callTo("61723164995779",true); |
| | | openSuccess = !openSuccess; |
| | | if(openSuccess){ |
| | | HDLLinphoneKit.getInstance().onOpenSuccess(); |
| | | }else{ |
| | | HDLLinphoneKit.getInstance().onOpenError("设备不在线"); |
| | | } |
| | | // openSuccess = !openSuccess; |
| | | // if(openSuccess){ |
| | | // HDLLinphoneKit.getInstance().onOpenSuccess(); |
| | | // }else{ |
| | | // HDLLinphoneKit.getInstance().onOpenError("设备不在线"); |
| | | // } |
| | | |
| | | |
| | | } |
| | |
| | | public void onScreenshotSuccessfulAction(Bitmap image) { |
| | | showToast("截图"); |
| | | } |
| | | }); |
| | | |
| | | @Override |
| | | public void onIncomingCall(String s) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |