From bca03b5f891af5966a06b1ecd00f6cd573659ce6 Mon Sep 17 00:00:00 2001 From: panlili2024 <14743743+panlili2024@user.noreply.gitee.com> Date: 星期四, 27 二月 2025 14:34:21 +0800 Subject: [PATCH] 兼容安卓14 --- HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneReverseCallActivity.java | 201 +++++++++++++++++++++++++++++-------------------- 1 files changed, 119 insertions(+), 82 deletions(-) diff --git a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneReverseCallActivity.java b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneReverseCallActivity.java index 362b933..e8aa861 100644 --- a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneReverseCallActivity.java +++ b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneReverseCallActivity.java @@ -1,16 +1,19 @@ package com.hdl.hdllinphonesdk.activity; +import android.Manifest; import android.content.Context; -import android.content.DialogInterface; +import android.content.IntentFilter; +import android.content.pm.PackageManager; 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.support.v7.app.AlertDialog; -import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.Log; @@ -28,6 +31,8 @@ import com.hdl.hdllinphonesdk.HDLLinphoneKit; import com.hdl.hdllinphonesdk.R; import com.hdl.hdllinphonesdk.callback.OnLPOpenDoorCallBack; +import com.hdl.hdllinphonesdk.dialog.LinphoneCommonDialog; +import com.hdl.hdllinphonesdk.receiver.CallBroadcastReceiver; import com.hdl.hdllinphonesdk.utils.HDLImageUtils; import com.hdl.hdllinphonesdk.utils.HDLLog; @@ -42,6 +47,7 @@ public class HDLLinphoneReverseCallActivity extends LPCheckPermissionsActivity implements View.OnClickListener { private static final String TAG = "HDLLinphoneReverseCallActivity"; + private RelativeLayout ll_lp_btn_back; //鎺т欢 private TextView tv_lp_title; private ImageView iv_lp_screenshot; @@ -53,6 +59,10 @@ private ImageView iv_lp_answer; private TextView tv_lp_answer; private RelativeLayout rl_lp_answerView; + + private ImageView iv_lp_rejectall; + private TextView tv_lp_rejectall; + private RelativeLayout rl_lp_rejectallView; private LinearLayout ll_video_lp_rendering; private TextureView video_lp_rendering; @@ -77,6 +87,11 @@ private String deviceSipAccount;//璁惧SIP璐﹀彿 private boolean enableVideo = false; + private CallBroadcastReceiver callBroadcastReceiver; + private IntentFilter callFilter; + + private boolean callAllRejection = false;//鑷爺闂ㄥ彛鏈烘槸鍚︽敮鎸佸叏閮ㄦ嫆鎺� + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -90,7 +105,6 @@ initCallBack(); initCountDownTimer(); initLinphone(); -// initVibrator(); } /** @@ -107,14 +121,19 @@ } //3.娉ㄩ攢callBack HDLLinphoneKit.getInstance().setOpenOpenDoorCallBack(null); - //4.鍙栨秷闇囧姩鍣� - cancelVibrator(); - //5. + + //4. if (mCountDownTimer != null) { mCountDownTimer.cancel(); mCountDownTimer = null; } onDestroyLinphone(); + + if (callBroadcastReceiver != null) { + unregisterReceiver(callBroadcastReceiver); + callBroadcastReceiver = null; + } + HDLLog.i(TAG, "onDestroy"); } @@ -122,6 +141,7 @@ * initView */ private void initView() { + ll_lp_btn_back = findViewById(R.id.ll_lp_btn_back); tv_lp_title = findViewById(R.id.tv_lp_title); iv_lp_screenshot = findViewById(R.id.iv_lp_screenshot); iv_lp_unlock = findViewById(R.id.iv_lp_unlock); @@ -130,6 +150,9 @@ iv_lp_answer = findViewById(R.id.iv_lp_answer); tv_lp_answer = findViewById(R.id.tv_lp_answer); rl_lp_answerView = findViewById(R.id.rl_lp_answerView); + iv_lp_rejectall = findViewById(R.id.iv_lp_hangUpall); + tv_lp_rejectall = findViewById(R.id.tv_lp_hangUpall); + rl_lp_rejectallView = findViewById(R.id.rl_lp_hangUpallView); ll_video_lp_rendering = findViewById(R.id.ll_video_lp_rendering); video_lp_rendering = findViewById(R.id.video_lp_rendering); video_lp_rendering2 = findViewById(R.id.video_lp_rendering2); @@ -147,12 +170,41 @@ */ private void initData() { Bundle extras = getIntent().getExtras(); + String interphoneType = ""; if (extras != null) { String titleName = extras.getString(HDLLinphoneKit.KEY_TITLE_NAME); if (!TextUtils.isEmpty(titleName)) { tv_lp_title.setText(titleName); } deviceSipAccount = extras.getString(HDLLinphoneKit.KEY_SIP_ACCOUNT); + interphoneType = extras.getString("interphoneType"); + callAllRejection = extras.getBoolean(HDLLinphoneKit.KEY_CALL_ALL_REJECTION); + } + + rl_lp_rejectallView.setVisibility(callAllRejection ? View.VISIBLE : View.GONE); + + //鐩戝惉鍛煎彨骞挎挱 + callFilter = new IntentFilter(); + callFilter.addAction("com.hdl.homepro.call.action"); + callBroadcastReceiver = new CallBroadcastReceiver(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + registerReceiver(callBroadcastReceiver, callFilter, RECEIVER_EXPORTED); + } else { + registerReceiver(callBroadcastReceiver, callFilter); + } + + if (callBroadcastReceiver != null) { + String finalInterphoneType = interphoneType; + callBroadcastReceiver.setOnReceivedCallBroadcastListener(new CallBroadcastReceiver.CallBroadcastListener() { + @Override + public void onReceived(String callFrom) { + //濡傛灉鏀跺埌鎺ㄩ�侀�氱煡鎶婄洃瑙嗛〉闈inish + if (!TextUtils.isEmpty(callFrom) && !finalInterphoneType.equals(callFrom)) { + Log.d("panlili", "HDLLinphoneIntercomActivity.java:onReceived-----> " + callFrom); + finish();//缁撴潫褰撳墠椤甸潰 + } + } + }); } } @@ -178,12 +230,15 @@ * init OnClickListener */ private void initOnClick() { + ll_lp_btn_back.setOnClickListener(this); iv_lp_screenshot.setOnClickListener(this); iv_lp_unlock.setOnClickListener(this); iv_lp_hangUp.setOnClickListener(this); tv_lp_hangUp.setOnClickListener(this); iv_lp_answer.setOnClickListener(this); tv_lp_answer.setOnClickListener(this); + iv_lp_rejectall.setOnClickListener(this); + tv_lp_rejectall.setOnClickListener(this); } /** @@ -232,8 +287,14 @@ public void onClick(View view) { int id = view.getId(); if (id == R.id.iv_lp_screenshot) { - //鎴浘 - onClickScreenshot(); + //鍔ㄦ�佹潈闄愮敵璇� + if (ContextCompat.checkSelfPermission(HDLLinphoneReverseCallActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED + && ActivityCompat.checkSelfPermission(HDLLinphoneReverseCallActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(HDLLinphoneReverseCallActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); + } else { + //鎴浘 + onClickScreenshot(); + } } else if (id == R.id.iv_lp_unlock) { //寮�閿� onClickUnlock(); @@ -243,6 +304,31 @@ } else if (id == R.id.iv_lp_answer || id == R.id.tv_lp_answer) { //鎺ュ惉 onClickAnswer(); + } else if (id == R.id.iv_lp_hangUpall || id == R.id.tv_lp_hangUpall) { + //鎷掓帴鍏ㄩ儴 + onClickRejectAll(); + } else if (id == R.id.ll_lp_btn_back) { + //杩斿洖鎸夐挳 鎸傛柇 + if (isAnswer) { + HDLLinphoneKit.getInstance().hangUp(); + } + finish(); + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + switch (requestCode) { + case 1: + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + //鎴浘 + onClickScreenshot(); + } else { + LinphoneCommonDialog.getInstance().showSettingPermissionDialog(HDLLinphoneReverseCallActivity.this, getString(R.string.open_save_permission)); + } + break; + default: } } @@ -266,37 +352,14 @@ * 寮�閿佺偣鍑讳簨浠� */ private void onClickUnlock() { - try { - AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.CustomAlertDialog); - builder.setTitle(R.string.lp_tipStr); - builder.setMessage(R.string.tip_confirm_unlock); - - builder.setPositiveButton(R.string.lp_confirm, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - // 鍦ㄧ‘瀹氭寜閽鐐瑰嚮鏃舵墽琛岀殑鎿嶄綔 - // 鍙互鍦ㄨ繖閲屾坊鍔犱綘鎯宠鎵ц鐨勯�昏緫 - if (HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener() != null) { - HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener().onUnlockAction(); - } - dialog.dismiss(); // 鍏抽棴寮圭獥 + LinphoneCommonDialog.getInstance().showDialog(HDLLinphoneReverseCallActivity.this, getString(R.string.tip_confirm_unlock), getString(R.string.lp_confirm), new LinphoneCommonDialog.OnOKClickListener() { + @Override + public void onOKClick() { + if (HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener() != null) { + HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener().onUnlockAction(); } - }); - builder.setNegativeButton(R.string.lp_cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - // 鍦ㄥ彇娑堟寜閽鐐瑰嚮鏃舵墽琛岀殑鎿嶄綔 - // 鍙互鍦ㄨ繖閲屾坊鍔犱綘鎯宠鎵ц鐨勯�昏緫 - dialog.dismiss(); // 鍏抽棴寮圭獥 - } - }); - - AlertDialog dialog = builder.create(); - dialog.show(); - } catch (Exception exception) { - Log.e(TAG, exception.getMessage()); - } - + } + }); } /** @@ -319,6 +382,19 @@ finish(); } + + /** + * 鎷掓帴鍏ㄩ儴鐐瑰嚮浜嬩欢 + */ + private void onClickRejectAll() { + //1.鍥炶皟浜嬩欢 + if (HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener() != null) { + HDLLinphoneKit.getInstance().getOnHDLLinphoneCallListener().onRejectCallAllAction(); + } + //2.椤甸潰鍏抽棴 + finish(); + } + /** * 鎺ュ惉鎸夐挳鐐瑰嚮浜嬩欢 */ @@ -330,12 +406,11 @@ } HDLLinphoneKit.getInstance().callTo(deviceSipAccount, true); - //2.鍙栨秷闇囧姩 - cancelVibrator(); - //3.淇敼UI + //2.淇敼UI isAnswer = true; tv_lp_hangUp.setText(getString(R.string.lp_hangupStr)); setViewGone(rl_lp_answerView); + setViewGone(rl_lp_rejectallView); setViewGone(tv_lp_calltime); setViewVisible(timer_lp_calltime); startCallTimeCountdown(); @@ -419,15 +494,9 @@ // Once call is finished (end state), terminate the activity // We also check for released state (called a few seconds later) just in case // we missed the first one + enableVideo = false; showToast(getString(R.string.lp_endOfCallStr)); finish(); - } else if (state == Call.State.StreamsRunning) { - if (HDLLinphoneKit.getInstance().getIntercomeType().equals(HDLLinphoneKit.INTER_PHONE_TYPE_HDL)) { - if (!enableVideo) { - enableVideo(core, call); - enableVideo = true; - } - } } } }; @@ -473,36 +542,4 @@ video_lp_rendering2 = null; } - /** - * 鍒濆鍖栭渿鍔ㄥ櫒 - */ - 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