Skip to content

Commit

Permalink
实现来电显示
Browse files Browse the repository at this point in the history
  • Loading branch information
ManTouBaby committed Oct 9, 2019
1 parent 65bc01e commit cfba25d
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 7 deletions.
6 changes: 6 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ repositories {
url "https://linphone.org/snapshots/maven_repository"
}
}

allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
Expand Down
17 changes: 12 additions & 5 deletions app/src/main/java/com/hrw/minelinphone/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
import android.widget.ImageView;

import com.hrw.linphonelibrary.LinPhoneHelper;
import com.hrw.linphonelibrary.call.CallBean;
import com.hrw.linphonelibrary.listener.OnLoginListener;

import org.linphone.core.Core;
import org.linphone.core.ProxyConfig;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
EditText mUser;
EditText mPassWord;
Expand All @@ -37,6 +41,10 @@ protected void onCreate(Bundle savedInstanceState) {
btVideoOutGo1 = (Button) findViewById(R.id.bt_video_out_go1);


List<CallBean> callBeans = new ArrayList<>();
callBeans.add(new CallBean("38110001", "人物名称1"));
callBeans.add(new CallBean("38110002", "人物名称2"));
LinPhoneHelper.getInstance().setCallList(callBeans);
btLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -46,26 +54,25 @@ public void onClick(View v) {
btVideoOutGo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LinPhoneHelper.getInstance().startVideoCall(MainActivity.this, "38110001","人物名称1");
LinPhoneHelper.getInstance().startVideoCall(MainActivity.this, "38110001", "人物名称1");
}
});
btOutGo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LinPhoneHelper.getInstance().startVoiceCall(MainActivity.this, "38110001","人物名称1");
LinPhoneHelper.getInstance().startVoiceCall(MainActivity.this, "38110001", "人物名称1");
}
});

btVideoOutGo1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LinPhoneHelper.getInstance().startVideoCall(MainActivity.this, "38110002","人物名称2");
LinPhoneHelper.getInstance().startVideoCall(MainActivity.this, "38110002", "人物名称2");
}
});
btOutGo1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LinPhoneHelper.getInstance().startVoiceCall(MainActivity.this, "38110002","人物名称2");
LinPhoneHelper.getInstance().startVoiceCall(MainActivity.this, "38110002", "人物名称2");
}
});
LinPhoneHelper.getInstance().addLoginListener(new OnLoginListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Intent;
import android.os.Handler;

import com.hrw.linphonelibrary.call.CallBean;
import com.hrw.linphonelibrary.call.CallHelper;
import com.hrw.linphonelibrary.call.CallOutGoingActivity;
import com.hrw.linphonelibrary.call.CallSetting;
Expand All @@ -19,6 +20,9 @@
import org.linphone.core.RegistrationState;
import org.linphone.core.TransportType;

import java.util.ArrayList;
import java.util.List;

import static java.lang.Thread.sleep;


Expand All @@ -29,6 +33,8 @@
* @desc:
*/
public class LinPhoneHelper {
private List<CallBean> mCallBeans = new ArrayList<>();

private AndroidAudioManager mAndroidAudioManager;
private static LinPhoneHelper mLinPhoneHelper;
private AccountCreator mAccountCreator;
Expand Down Expand Up @@ -110,6 +116,21 @@ private void dealAfterCall() {
mCallSetting.setAutomaticallyAcceptVideoRequests(true);
}

public void setCallList(List<CallBean> mCallBeans) {
this.mCallBeans = mCallBeans;
}

public String getCallNameByNumber(String callNumber) {
String callName = null;
for (CallBean callBean : mCallBeans) {
if (callBean.getCallNumber().equals(callNumber)) {
callName = callBean.getCallName();
break;
}
}
return callName;
}

public CallHelper getCallHelper() {
return mCallHelper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
Intent intent = getIntent();
mCallName = intent.getStringExtra(ParamTag.CALL_NAME);
mCallNumber = intent.getStringExtra(ParamTag.CALL_NUMBER);
tvCallName.setText(mCallName);
String callResult = LinPhoneHelper.getInstance().getCallNameByNumber(mCallName);
tvCallName.setText(callResult == null ? mCallName : callResult);
tvCallNumber.setText(mCallNumber);

mCore.setNativeVideoWindowId(ttvOtherVideo);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.hrw.linphonelibrary.call;

/**
* @version 1.0.0
* @author:hrw
* @date:2019/10/09 15:18
* @desc:
*/
public class CallBean {
private String callNumber;
private String callName;


public CallBean(String callNumber, String callName) {
this.callNumber = callNumber;
this.callName = callName;
}

public String getCallNumber() {
return callNumber;
}

public void setCallNumber(String callNumber) {
this.callNumber = callNumber;
}

public String getCallName() {
return callName;
}

public void setCallName(String callName) {
this.callName = callName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import com.hrw.linphonelibrary.R;
import com.hrw.linphonelibrary.call.CallIncomingActivity;
import com.hrw.linphonelibrary.call.ParamTag;

import org.linphone.core.Call;
import org.linphone.core.Core;
Expand Down Expand Up @@ -75,10 +76,12 @@ public void onCreate() {
mCoreListener = new CoreListenerStub() {
@Override
public void onCallStateChanged(Core core, Call call, Call.State state, String message) {
System.out.println( message + "--" + state.toInt());
System.out.println(message + "--" + state.toInt());
if (state == Call.State.IncomingReceived) {
Intent intent = new Intent(LinPhoneService.this, CallIncomingActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(ParamTag.CALL_NUMBER, call.getRemoteAddress().getUsername());
intent.putExtra(ParamTag.CALL_NAME, call.getRemoteAddress().getDisplayName());
startActivity(intent);
}
}
Expand Down

0 comments on commit cfba25d

Please sign in to comment.