From 357b934aa50e51148d14ff238919868095a45afd Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期二, 24 八月 2021 10:15:17 +0800 Subject: [PATCH] 2021-08-24 1.呼叫页面增加震动提醒 --- HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneIntercomActivity.java | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 54 insertions(+), 5 deletions(-) diff --git a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneIntercomActivity.java b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneIntercomActivity.java index f076514..397b8ce 100644 --- a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneIntercomActivity.java +++ b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneIntercomActivity.java @@ -5,9 +5,12 @@ import android.content.Intent; import android.content.IntentFilter; import android.graphics.Bitmap; +import android.media.AudioAttributes; +import android.os.Build; import android.os.Bundle; import android.os.CountDownTimer; import android.os.SystemClock; +import android.os.Vibrator; import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.Log; @@ -60,11 +63,16 @@ //鍙傛暟 private boolean isAnswer;//鏄惁宸茬粡鎺ュ惉浜� private int callTime;//閫氳瘽鏃堕棿 - + //鍊掕鏃� private CountDownTimer mCountDownTimer; + /** + * 鎵嬫満鎸姩鍣� + */ + private Vibrator mVibrator; //Linphone private CoreListenerStub mCoreListener; + @Override protected void onCreate(Bundle savedInstanceState) { @@ -79,6 +87,7 @@ initCallBack(); initCountDownTimer(); initLinphone(); + initVibrator(); } @@ -90,17 +99,20 @@ super.onDestroy(); //1.鎸傛柇 HDLLinphoneKit.getInstance().hangUp(); - + //2.鏆傚仠璁℃椂 if (null != timer_lp_calltime) { timer_lp_calltime.stop(); } - + //3.娉ㄩ攢callBack HDLLinphoneKit.getInstance().setOpenOpenDoorCallBack(null); - + //4.鍙栨秷闇囧姩鍣� + cancelVibrator(); + //5. if (mCountDownTimer != null) { mCountDownTimer.cancel(); mCountDownTimer = null; } + //5. onDestroyLinphone(); HDLLog.i(TAG, "onDestroy"); @@ -127,6 +139,8 @@ timer_lp_calltime = (Chronometer) findViewById(R.id.timer_lp_calltime); tv_lp_calltime = findViewById(R.id.tv_lp_calltime); setWidthHeightWithRatio(ll_video_lp_rendering, 16, 9); + + } /** @@ -286,6 +300,9 @@ private void onClickAnswer() { //1.鎺ュ惉 HDLLinphoneKit.getInstance().acceptCall(); + //2.鍙栨秷闇囧姩 + cancelVibrator(); + //3.淇敼UI isAnswer = true; tv_lp_hangUp.setText(getString(R.string.lp_hangupStr)); setViewGone(rl_lp_answerView); @@ -389,7 +406,7 @@ /** * onDestroyLinphone */ - void onDestroyLinphone(){ + void onDestroyLinphone() { Core core = HDLLinphoneKit.getInstance().getCore(); if (core != null) { core.removeListener(mCoreListener); @@ -401,4 +418,36 @@ } + /** + * 鍒濆鍖栭渿鍔ㄥ櫒 + */ + void initVibrator() { + mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); + if (mVibrator.hasVibrator()) { + long[] patern = {0, 1000, 1000}; + AudioAttributes audioAttributes = null; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + audioAttributes = new AudioAttributes.Builder() + .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) + .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE) //key + .build(); + mVibrator.vibrate(patern, 1, audioAttributes); + } else { + mVibrator.vibrate(patern, 1); + } + } else { + HDLLog.E("褰撳墠鎵嬫満娌℃湁闇囧姩鍣�"); + } + } + + /** + * 鍏抽棴闇囧姩鍣� + */ + void cancelVibrator(){ + if(mVibrator != null){ + mVibrator.cancel(); + mVibrator = null; + } + + } } \ No newline at end of file -- Gitblit v1.8.0