Android 拨打电话或视频通话函数
private final String Tag = "callTel";
@UniJSMethod(uiThread = false)
public void callTel(JSONObject options,UniJSCallback callback){
Log.e(Tag, "callTel");
try{
String tel = options.getString("tel");
String callType = options.getString("callType");
Context context = mUniSDKInstance.getContext();
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+tel));
if(callType.equals("video")){
intent.putExtra(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, VideoProfile.STATE_BIDIRECTIONAL);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
((Activity)context).startActivity(intent);
Log.e(Tag, "callTel ok");
if (callback != null) {
JSONObject data = createCallbackData(success_code,success_text);
callback.invoke(data);
}
}
catch (Exception e){
if(callback!=null) {
JSONObject data = createCallbackData(fail_code, String.valueOf(e));
callback.invoke(data);
}
Log.e(Tag, "Exception:"+e);
}
}
Android 挂断电话 函数
@UniJSMethod(uiThread = false)
public void endCall(UniJSCallback callback){
Log.e(Tag, "endCall");
Context context = mUniSDKInstance.getContext();
try {
TelephonyManager telManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Method method = telManager.getClass().getDeclaredMethod("endCall");
method.invoke(telManager);
if(callback!=null) {
JSONObject data = createCallbackData(success_code, success_text);
callback.invoke(data);
}
Log.e(Tag, "endCall ok");
} catch (Exception e) {
Log.e(Tag, "endCall Exception:"+e);
if(callback!=null) {
JSONObject data = createCallbackData(fail_code, String.valueOf(e));
callback.invoke(data);
}
}
}
UniApp手机端调用App原生语言插件
export function call (tel,callType){
return new Promise((resolve)=>{
const plugin = uni.requireNativePlugin('PluginName')
if (!plugin) {
uni.showToast({
icon: 'none',
title: '插件引入失败'
})
resolve({code:0,data:'插件引入失败'})
return
}
plugin.callTel({tel,callType},(res) => {
console.log('callTel:', res);
resolve(res)
})
})
}
export function endCall (){
console.log('endCall')
return new Promise((resolve)=>{
const plugin = uni.requireNativePlugin('PluginName')
if (!plugin) {
uni.showToast({
icon: 'none',
title: '插件引入失败'
})
resolve({code:0,data:'插件引入失败'})
return
}
plugin.endCall((res) => {
console.log('endCall:', res);
resolve(res)
})
})
}