接听挂断电话

This commit is contained in:
GYJ
2024-11-28 13:49:26 +08:00
parent 1da1683adc
commit b6cd0d0f2b
13 changed files with 305 additions and 13 deletions

View File

@@ -17,6 +17,8 @@ import org.json.JSONObject;
import java.text.SimpleDateFormat;
import java.util.Date;
import cn.kaer.callmodule.ctrl.CallController;
import cn.kaer.callmodule.exceptions.CallException;
import io.flutter.Log;
public class CallManager {
@@ -68,4 +70,22 @@ public class CallManager {
broad.putExtra("callLog", callLogArray.toString());
mainActivityContext.sendBroadcast(broad);
}
public static void acceptCall() {
try {
CallController.get().answer();
} catch (CallException e) {
e.printStackTrace();
}
}
public static void rejectCall() {
try {
CallController.get().term();
} catch (CallException e) {
e.printStackTrace();
}
}
public static void endCall() {}
}

View File

@@ -8,6 +8,9 @@ public class ChannelNames {
public static final String CALL_LOG_CALLBACK = "callLogCallback";
public static final String CALL_STATUS_CHANGE = "callStatusChange";
public static final String ACCEPT_CALL = "acceptCall";
public static final String REJECT_CALL = "rejectCall";
public static final String END_CALL = "endCall";
public static String getChannelName(String name) {
return BASE_NAME + name;

View File

@@ -8,6 +8,9 @@ import io.flutter.plugin.common.MethodChannel;
public class MessageChannel {
public static void addMessageChannel(BinaryMessenger messenger) {
callLogChannel(messenger);
acceptCallChannel(messenger);
rejectCallChannel(messenger);
endCallChannel(messenger);
}
public static void callLogChannel(BinaryMessenger messenger) {
@@ -26,4 +29,55 @@ public class MessageChannel {
};
});
}
public static void acceptCallChannel(BinaryMessenger messenger) {
if (messenger == null) {
return;
}
MethodChannel methodChannel = new MethodChannel(messenger, ChannelNames.getChannelName(ChannelNames.ACCEPT_CALL));
methodChannel.setMethodCallHandler((call, result) -> {
System.out.println("call.method: " + call.method);
if (call.method.equals(ChannelNames.ACCEPT_CALL)) {
System.out.println("接听电话");
result.success(null);
CallManager.acceptCall();
}
});
}
public static void rejectCallChannel(BinaryMessenger messenger) {
if (messenger == null) {
return;
}
MethodChannel methodChannel = new MethodChannel(messenger, ChannelNames.getChannelName(ChannelNames.REJECT_CALL));
methodChannel.setMethodCallHandler((call, result) -> {
System.out.println("call.method: " + call.method);
if (call.method.equals(ChannelNames.REJECT_CALL)) {
System.out.println("拒接电话");
result.success(null);
CallManager.rejectCall();
}
});
}
public static void endCallChannel(BinaryMessenger messenger) {
if (messenger == null) {
return;
}
MethodChannel methodChannel = new MethodChannel(messenger, ChannelNames.getChannelName(ChannelNames.END_CALL));
methodChannel.setMethodCallHandler((call, result) -> {
System.out.println("call.method: " + call.method);
if (call.method.equals(ChannelNames.END_CALL)) {
System.out.println("结束通话");
result.success(null);
CallManager.endCall();
}
});
}
}