Commit 5df18524 by zhengnw@sobot.com

baseactivity 适配android13 权限

parent 88c9d5e2
......@@ -3,7 +3,7 @@ plugins {
}
android {
compileSdkVersion 29
compileSdkVersion 33
defaultConfig {
minSdkVersion 16
......
......@@ -13,7 +13,7 @@ ext {
PUBLISH_GROUP_ID = "com.sobot.library" //项目包名
PUBLISH_ARTIFACT_ID = 'widget' //项目名
// PUBLISH_ARTIFACT_ID = 'widget_x' //项目名
PUBLISH_VERSION = '1.0.2' //版本号
PUBLISH_VERSION = '1.0.3' //版本号
}
......
......@@ -6,6 +6,9 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="com.google.android.apps.photos.permission.GOOGLE_PHOTOS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
......
......@@ -12,6 +12,7 @@ import android.hardware.Camera;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
......@@ -38,6 +39,7 @@ import com.sobot.widget.ui.permission.SobotPermissionListener;
import com.sobot.widget.ui.permission.SobotPermissionListenerImpl;
import com.sobot.widget.ui.permission.SobotPermissionTipDialog;
import com.sobot.widget.ui.statusbar.SobotStatusBarUtils;
import com.sobot.widget.ui.toast.SobotToastUtil;
import com.sobot.widget.ui.utils.SobotResourceUtils;
import com.sobot.widget.ui.utils.SobotWidgetUtils;
......@@ -52,7 +54,7 @@ public abstract class SobotBaseActivity extends FragmentActivity {
//相机拍照后返回的照片
protected File cameraFile;
//权限回调
public SobotPermissionListener sobotPermissionListener;
public SobotPermissionListener permissionListener;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
......@@ -450,97 +452,92 @@ public abstract class SobotBaseActivity extends FragmentActivity {
}
/**
* 检测是否需要弹出权限用途提示框pop,如果弹出,则拦截接下来的处理逻辑,自己处理
*
* @param title
* @param content
* @param type
* @return
*/
public boolean checkIsShowPermissionPop(String title, String content, final int type) {
if (SobotWidgetApi.getSwitchMarkStatus(SobotMarkConfig.SHOW_PERMISSION_TIPS_POP)) {
if (!isHasPermission(type)) {
SobotPermissionTipDialog dialog = new SobotPermissionTipDialog(getSobotBaseActivity(), title, content, new SobotPermissionTipDialog.ClickViewListener() {
@Override
public void clickRightView(Context context, SobotPermissionTipDialog dialog) {
dialog.dismiss();
if (type == 1) {
if (!checkStoragePermission()) {
return;
}
} else if (type == 2) {
if (!checkAudioPermission()) {
return;
}
} else if (type == 3) {
if (!checkAudioAndCameraPermission()) {
return;
}
} else if (type == 4) {
if (!checkCameraPermission()) {
return;
}
}
}
@Override
public void clickLeftView(Context context, SobotPermissionTipDialog dialog) {
dialog.dismiss();
}
});
dialog.show();
return true;
}
}
return false;
}
/**
* 判断是否有权限
*
* @param type 1 存储;2 麦克风;3 拍摄;4 系统拍照;
* @return true, 已经获取权限;false,没有权限
*/
protected boolean isHasPermission(int type) {
if (type == 1) {
return isHasStoragePermission();
} else if (type == 2) {
return isHasAudioPermission();
} else if (type == 3) {
return isHasCameraPermission();
} else if (type == 4) {
return isHasSySCameraPermission();
}
return true;
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case SobotBaseConstant.SOBOT_CODE_PERMISSIONS_REQUEST:
case SobotBaseConstant.REQUEST_CODE_PICTURE:
try {
for (int i = 0; i < grantResults.length; i++) {
//判断权限的结果,如果有被拒绝,就return
if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
String permissionTitle = "sobot_no_permission_text";
String permissionTitle = getResources().getString(R.string.sobot_no_permission_text);
if (permissions[i] != null && permissions[i].equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
permissionTitle = "sobot_no_write_external_storage_permission";
permissionTitle = getResources().getString(R.string.sobot_no_write_external_storage_permission);
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) && !SobotWidgetApi.getSwitchMarkStatus(SobotMarkConfig.SHOW_PERMISSION_TIPS_POP)) {
SobotToastUtil.showCustomLongToast(this, SobotSystemUtils.getAppName(this) + getResources().getString(R.string.sobot_want_use_your) + getResources().getString(R.string.sobot_memory_card) + " , " + getResources().getString(R.string.sobot_memory_card_yongtu));
} else {
//调用权限失败
if (permissionListener != null) {
permissionListener.onPermissionErrorListener(this, permissionTitle);
}
}
} else if (permissions[i] != null && permissions[i].equals(Manifest.permission.READ_EXTERNAL_STORAGE)) {
permissionTitle = getResources().getString(R.string.sobot_no_write_external_storage_permission);
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE) && !SobotWidgetApi.getSwitchMarkStatus(SobotMarkConfig.SHOW_PERMISSION_TIPS_POP)) {
SobotToastUtil.showCustomLongToast(this, SobotSystemUtils.getAppName(this) + getResources().getString(R.string.sobot_want_use_your) + getResources().getString(R.string.sobot_memory_card) + " , " + getResources().getString(R.string.sobot_memory_card_yongtu));
} else {
//调用权限失败
if (permissionListener != null) {
permissionListener.onPermissionErrorListener(this, permissionTitle);
}
}
} else if (permissions[i] != null && permissions[i].equals(Manifest.permission.RECORD_AUDIO)) {
permissionTitle = "sobot_no_record_audio_permission";
permissionTitle = getResources().getString(R.string.sobot_no_record_audio_permission);
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.RECORD_AUDIO) && !SobotWidgetApi.getSwitchMarkStatus(SobotMarkConfig.SHOW_PERMISSION_TIPS_POP)) {
SobotToastUtil.showCustomLongToast(this, SobotSystemUtils.getAppName(this) + getResources().getString(R.string.sobot_want_use_your) + getResources().getString(R.string.sobot_microphone) + " , " + getString(R.string.sobot_microphone_yongtu));
} else {
//调用权限失败
if (permissionListener != null) {
permissionListener.onPermissionErrorListener(this, permissionTitle);
}
}
} else if (permissions[i] != null && permissions[i].equals(Manifest.permission.CAMERA)) {
permissionTitle = "sobot_no_camera_permission";
}
//只有全部权限允许,我们才走回调。
if (sobotPermissionListener != null) {
sobotPermissionListener.onPermissionErrorListener(this, getResString(permissionTitle));
permissionTitle = getResources().getString(R.string.sobot_no_camera_permission);
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA) && !SobotWidgetApi.getSwitchMarkStatus(SobotMarkConfig.SHOW_PERMISSION_TIPS_POP)) {
SobotToastUtil.showCustomLongToast(this, SobotSystemUtils.getAppName(this) + getResources().getString(R.string.sobot_want_use_your) + getString(R.string.sobot_camera) + " , " + getString(R.string.sobot_camera_yongtu));
} else {
//调用权限失败
if (permissionListener != null) {
permissionListener.onPermissionErrorListener(this, permissionTitle);
}
}
} else if (permissions[i] != null && permissions[i].equals(Manifest.permission.READ_MEDIA_IMAGES)) {
permissionTitle = getResources().getString(R.string.sobot_no_write_external_storage_permission);
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_MEDIA_IMAGES) && !SobotWidgetApi.getSwitchMarkStatus(SobotMarkConfig.SHOW_PERMISSION_TIPS_POP)) {
SobotToastUtil.showCustomLongToast(this, SobotSystemUtils.getAppName(this) + getResources().getString(R.string.sobot_want_use_your) + getString(R.string.sobot_memory_card) + " , " + getString(R.string.sobot_memory_card_yongtu));
} else {
//调用权限失败
if (permissionListener != null) {
permissionListener.onPermissionErrorListener(getSobotBaseActivity(), permissionTitle);
}
}
} else if (permissions[i] != null && permissions[i].equals(Manifest.permission.READ_MEDIA_VIDEO)) {
permissionTitle = getResources().getString(R.string.sobot_no_write_external_storage_permission);
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_MEDIA_VIDEO) && !SobotWidgetApi.getSwitchMarkStatus(SobotMarkConfig.SHOW_PERMISSION_TIPS_POP)) {
SobotToastUtil.showCustomLongToast(this, SobotSystemUtils.getAppName(this) + getResources().getString(R.string.sobot_want_use_your) + getString(R.string.sobot_memory_card) + " , " + getString(R.string.sobot_memory_card_yongtu));
} else {
//调用权限失败
if (permissionListener != null) {
permissionListener.onPermissionErrorListener(getSobotBaseActivity(), permissionTitle);
}
}
} else if (permissions[i] != null && permissions[i].equals(Manifest.permission.READ_MEDIA_AUDIO)) {
permissionTitle = getResources().getString(R.string.sobot_no_write_external_storage_permission);
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_MEDIA_AUDIO) && !SobotWidgetApi.getSwitchMarkStatus(SobotMarkConfig.SHOW_PERMISSION_TIPS_POP)) {
SobotToastUtil.showCustomLongToast(this, SobotSystemUtils.getAppName(this) + getResources().getString(R.string.sobot_want_use_your) + getString(R.string.sobot_memory_card) + " , " + getString(R.string.sobot_memory_card_yongtu));
} else {
//调用权限失败
if (permissionListener != null) {
permissionListener.onPermissionErrorListener(getSobotBaseActivity(), permissionTitle);
}
}
}
return;
}
}
if (sobotPermissionListener != null) {
sobotPermissionListener.onPermissionSuccessListener();
if (permissionListener != null) {
permissionListener.onPermissionSuccessListener();
}
} catch (Exception e) {
// e.printStackTrace();
......@@ -552,26 +549,58 @@ public abstract class SobotBaseActivity extends FragmentActivity {
/**
* 检查存储权限
*
* @param checkType 0:图片权限 1:视频权限,2:音频权限,3,所有细分的权限, android 13 使用
* @return true, 已经获取权限;false,没有权限,尝试获取
*/
protected boolean checkStoragePermission() {
if (Build.VERSION.SDK_INT >= 29 && SobotSystemUtils.getTargetSdkVersion(getSobotBaseActivity()) >= 29) {
//分区存储 从andrid10手机开始 TargetSdkVersion >= 29,不需要文件存储权限
return true;
}
if (Build.VERSION.SDK_INT >= 23 && SobotSystemUtils.getTargetSdkVersion(getSobotBaseActivity()) >= 23) {
protected boolean checkStoragePermission(int checkType) {
//如果是升级Android13之前就已经具有读写SDK的权限,那么升级到13之后,自己具有上述三个权限。
//如果是升级Android13之后新装的应用,并且targetSDK小于33,则申请READ_EXTERNAL_STORAGE权限时,会自动转化为对上述三个权限的申请,权限申请框只一个
//如果是升级Android13之后新装的应用,并且targetSDK大于等于33,则申请READ_EXTERNAL_STORAGE权限时会自动拒绝(同理WRITE_EXTERNAL_STORAGE也是一样)。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (checkType == 0) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_IMAGES)
!= PackageManager.PERMISSION_GRANTED) {
//申请图片权限
this.requestPermissions(new String[]{Manifest.permission.READ_MEDIA_IMAGES}, SobotBaseConstant.REQUEST_CODE_PICTURE);
return false;
}
} else if (checkType == 1) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VIDEO)
!= PackageManager.PERMISSION_GRANTED) {
//申请视频权限
this.requestPermissions(new String[]{Manifest.permission.READ_MEDIA_VIDEO}, SobotBaseConstant.REQUEST_CODE_PICTURE);
return false;
}
} else if (checkType == 2) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_AUDIO)
!= PackageManager.PERMISSION_GRANTED) {
//申请音频权限
this.requestPermissions(new String[]{Manifest.permission.READ_MEDIA_AUDIO}, SobotBaseConstant.REQUEST_CODE_PICTURE);
return false;
}
} else {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_IMAGES)
!= PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VIDEO)
!= PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_AUDIO)
!= PackageManager.PERMISSION_GRANTED) {
//申请:图片权限 视频权限 音频权限
this.requestPermissions(new String[]{Manifest.permission.READ_MEDIA_AUDIO, Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.READ_MEDIA_VIDEO}, SobotBaseConstant.REQUEST_CODE_PICTURE);
return false;
}
}
} else if (Build.VERSION.SDK_INT >= 23 && SobotSystemUtils.getTargetSdkVersion(getSobotBaseActivity().getApplicationContext()) >= 23) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
//申请WRITE_EXTERNAL_STORAGE权限
this.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE
, Manifest.permission.READ_EXTERNAL_STORAGE}, SobotBaseConstant.SOBOT_CODE_PERMISSIONS_REQUEST);
, Manifest.permission.READ_EXTERNAL_STORAGE}, SobotBaseConstant.REQUEST_CODE_PICTURE);
return false;
}
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
//申请READ_EXTERNAL_STORAGE权限
this.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE
, Manifest.permission.READ_EXTERNAL_STORAGE}, SobotBaseConstant.SOBOT_CODE_PERMISSIONS_REQUEST);
, Manifest.permission.READ_EXTERNAL_STORAGE}, SobotBaseConstant.REQUEST_CODE_PICTURE);
return false;
}
}
......@@ -581,14 +610,35 @@ public abstract class SobotBaseActivity extends FragmentActivity {
/**
* 判断是否有存储卡权限
*
* @param checkPermissionType 0:图片权限 1:视频权限,2:音频权限,3,所有细分的权限, android 13 使用
* @return true, 已经获取权限;false,没有权限
*/
protected boolean isHasStoragePermission() {
if (Build.VERSION.SDK_INT >= 29 && SobotSystemUtils.getTargetSdkVersion(getSobotBaseActivity()) >= 29) {
//分区存储 从andrid10手机开始 TargetSdkVersion >= 29,情况不需要文件存储权限
return true;
}
if (Build.VERSION.SDK_INT >= 23 && SobotSystemUtils.getTargetSdkVersion(getSobotBaseActivity()) >= 23) {
protected boolean isHasStoragePermission(int checkPermissionType) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (checkPermissionType == 0) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_IMAGES)
!= PackageManager.PERMISSION_GRANTED) {
return false;
}
} else if (checkPermissionType == 1) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VIDEO)
!= PackageManager.PERMISSION_GRANTED) {
return false;
}
} else if (checkPermissionType == 2) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_AUDIO)
!= PackageManager.PERMISSION_GRANTED) {
return false;
}
} else {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_IMAGES)
!= PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VIDEO)
!= PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_AUDIO)
!= PackageManager.PERMISSION_GRANTED) {
return false;
}
}
} else if (Build.VERSION.SDK_INT >= 23 && SobotSystemUtils.getTargetSdkVersion(getSobotBaseActivity().getApplicationContext()) >= 23) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
......@@ -604,11 +654,11 @@ public abstract class SobotBaseActivity extends FragmentActivity {
* @return true, 已经获取权限;false,没有权限,尝试获取
*/
protected boolean checkAudioPermission() {
if (Build.VERSION.SDK_INT >= 23 && SobotSystemUtils.getTargetSdkVersion(getSobotBaseActivity()) >= 23) {
if (Build.VERSION.SDK_INT >= 23 && SobotSystemUtils.getTargetSdkVersion(getSobotBaseActivity().getApplicationContext()) >= 23) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.RECORD_AUDIO)
!= PackageManager.PERMISSION_GRANTED) {
this.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO},
SobotBaseConstant.SOBOT_CODE_PERMISSIONS_REQUEST);
SobotBaseConstant.REQUEST_CODE_PICTURE);
return false;
}
}
......@@ -621,32 +671,9 @@ public abstract class SobotBaseActivity extends FragmentActivity {
* @return true, 已经获取权限;false,没有权限
*/
protected boolean isHasAudioPermission() {
if (Build.VERSION.SDK_INT >= 23 && SobotSystemUtils.getTargetSdkVersion(getSobotBaseActivity()) >= 23) {
if (!isHasStoragePermission() || ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.RECORD_AUDIO)
!= PackageManager.PERMISSION_GRANTED) {
return false;
}
}
return true;
}
/**
* 检查拍摄权限
*
* @return true, 已经获取权限;false,没有权限,尝试获取
*/
protected boolean checkAudioAndCameraPermission() {
if (Build.VERSION.SDK_INT >= 23 && SobotSystemUtils.getTargetSdkVersion(getSobotBaseActivity()) >= 23) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
this.requestPermissions(new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO}
, SobotBaseConstant.SOBOT_CODE_PERMISSIONS_REQUEST);
return false;
}
if (Build.VERSION.SDK_INT >= 23 && SobotSystemUtils.getTargetSdkVersion(getSobotBaseActivity().getApplicationContext()) >= 23) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.RECORD_AUDIO)
!= PackageManager.PERMISSION_GRANTED) {
this.requestPermissions(new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO}
, SobotBaseConstant.SOBOT_CODE_PERMISSIONS_REQUEST);
return false;
}
}
......@@ -654,32 +681,16 @@ public abstract class SobotBaseActivity extends FragmentActivity {
}
/**
* 判断是否有拍摄权限
*
* @return true, 已经获取权限;false,没有权限
*/
protected boolean isHasCameraPermission() {
if (Build.VERSION.SDK_INT >= 23 && SobotSystemUtils.getTargetSdkVersion(getSobotBaseActivity()) >= 23) {
if (!isHasStoragePermission() || ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.RECORD_AUDIO)
!= PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
return false;
}
}
return true;
}
/**
* 检查拍照权限
* 检查相机权限
*
* @return true, 已经获取权限;false,没有权限,尝试获取
*/
protected boolean checkCameraPermission() {
if (Build.VERSION.SDK_INT >= 23 && SobotSystemUtils.getTargetSdkVersion(getSobotBaseActivity()) >= 23) {
if (Build.VERSION.SDK_INT >= 23 && SobotSystemUtils.getTargetSdkVersion(getSobotBaseActivity().getApplicationContext()) >= 23) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
this.requestPermissions(new String[]{Manifest.permission.CAMERA},
SobotBaseConstant.SOBOT_CODE_PERMISSIONS_REQUEST);
this.requestPermissions(new String[]{Manifest.permission.CAMERA}
, SobotBaseConstant.REQUEST_CODE_PICTURE);
return false;
}
}
......@@ -691,9 +702,9 @@ public abstract class SobotBaseActivity extends FragmentActivity {
*
* @return true, 已经获取权限;false,没有权限
*/
protected boolean isHasSySCameraPermission() {
if (Build.VERSION.SDK_INT >= 23 && SobotSystemUtils.getTargetSdkVersion(getSobotBaseActivity()) >= 23) {
if (!isHasStoragePermission() || ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.CAMERA)
protected boolean isHasCameraPermission() {
if (Build.VERSION.SDK_INT >= 23 && SobotSystemUtils.getTargetSdkVersion(getSobotBaseActivity().getApplicationContext()) >= 23) {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
return false;
}
......@@ -701,98 +712,103 @@ public abstract class SobotBaseActivity extends FragmentActivity {
return true;
}
/**
* 从图库获取图片
*/
public void selectPicFromLocal() {
selectPicFromLocal("", "");
}
/**
* 从图库获取图片
*
* @param title 权限用途提示弹窗开启后,弹窗的的标题
* @param content 权限用途提示弹窗开启后,弹窗的内容
*/
public void selectPicFromLocal(String title, String content) {
sobotPermissionListener = null;
sobotPermissionListener = new SobotPermissionListenerImpl() {
public void selectPicFromLocal() {
permissionListener = new SobotPermissionListenerImpl() {
@Override
public void onPermissionSuccessListener() {
SobotWidgetUtils.openSelectPic(getSobotBaseActivity());
}
};
if (checkIsShowPermissionPop(getResString("sobot_memory_card"), getResString("sobot_memory_card_yongtu"), 1)) {
if (checkIsShowPermissionPop(getString(R.string.sobot_memory_card), getString(R.string.sobot_memory_card_yongtu), 1, 0)) {
return;
}
if (!checkStoragePermission()) {
if (!checkStoragePermission(0)) {
return;
}
SobotWidgetUtils.openSelectPic(this);
SobotWidgetUtils.openSelectPic(getSobotBaseActivity());
}
/**
* 从图库获取视频
* 判断是否有存储卡权限
*
* @param type 1 存储卡;2 麦克风;3 相机;
* @param checkPermissionType 0:图片权限 1:视频权限,2:音频权限,3,所有细分的权限, android 13 使用
* @return true, 已经获取权限;false,没有权限
*/
public void selectVedioFromLocal() {
selectVedioFromLocal("", "");
protected boolean isHasPermission(int type, int checkPermissionType) {
if (type == 1) {
return isHasStoragePermission(checkPermissionType);
} else if (type == 2) {
return isHasAudioPermission();
} else if (type == 3) {
return isHasCameraPermission();
}
return true;
}
/**
* 从图库获取视频
* 检测是否需要弹出权限用途提示框pop,如果弹出,则拦截接下来的处理逻辑,自己处理
*
* @param title 权限用途提示弹窗开启后,弹窗的的标题
* @param content 权限用途提示弹窗开启后,弹窗的内容
* @param title
* @param content
* @param type
* @param checkPermissionType 0:图片权限 1:视频权限,2:音频权限,3,所有细分的权限, android 13 使用
* @return
*/
public void selectVedioFromLocal(String title, String content) {
sobotPermissionListener = null;
sobotPermissionListener = new SobotPermissionListenerImpl() {
@Override
public void onPermissionSuccessListener() {
SobotWidgetUtils.openSelectVedio(getSobotBaseActivity());
public boolean checkIsShowPermissionPop(String title, String content, final int type, final int checkPermissionType) {
if (SobotWidgetApi.getSwitchMarkStatus(SobotMarkConfig.SHOW_PERMISSION_TIPS_POP)) {
if (!isHasPermission(type, checkPermissionType)) {
SobotPermissionTipDialog dialog = new SobotPermissionTipDialog(getSobotBaseActivity(), title, content, new SobotPermissionTipDialog.ClickViewListener() {
@Override
public void clickRightView(Context context, SobotPermissionTipDialog dialog) {
dialog.dismiss();
if (type == 1) {
if (!checkStoragePermission(checkPermissionType)) {
return;
}
} else if (type == 2) {
if (!checkAudioPermission()) {
return;
}
} else if (type == 3) {
if (!checkCameraPermission()) {
return;
}
}
}
@Override
public void clickLeftView(Context context, SobotPermissionTipDialog dialog) {
dialog.dismiss();
}
});
dialog.show();
return true;
}
};
if (checkIsShowPermissionPop(getResString("sobot_memory_card"), getResString("sobot_memory_card_yongtu"), 1)) {
return;
}
if (!checkStoragePermission()) {
return;
}
SobotWidgetUtils.openSelectVedio(getSobotBaseActivity());
}
/**
* 打开相机
*/
public void openCamera() {
openCamera("", "");
return false;
}
/**
* 打开相机
*
* @param title 权限用途提示弹窗开启后,弹窗的的标题
* @param content 权限用途提示弹窗开启后,弹窗的内容
* 从图库获取视频
*/
public void openCamera(String title, String content) {
cameraFile = null;
sobotPermissionListener = null;
sobotPermissionListener = new SobotPermissionListenerImpl() {
public void selectVedioFromLocal() {
permissionListener = new SobotPermissionListenerImpl() {
@Override
public void onPermissionSuccessListener() {
if (isCameraCanUse()) {
cameraFile = SobotWidgetUtils.openCamera(getSobotBaseActivity());
}
SobotWidgetUtils.openSelectVedio(getSobotBaseActivity());
}
};
if (checkIsShowPermissionPop(TextUtils.isEmpty(title) ? getResString("sobot_camera") : title, TextUtils.isEmpty(content) ? getResString("sobot_camera_yongtu") : content, 4)) {
if (checkIsShowPermissionPop(getString(R.string.sobot_memory_card), getString(R.string.sobot_memory_card_yongtu), 1, 1)) {
return;
}
if (!checkCameraPermission()) {
if (!checkStoragePermission(1)) {
return;
}
if (isCameraCanUse()) {
cameraFile = SobotWidgetUtils.openCamera(getSobotBaseActivity());
}
SobotWidgetUtils.openSelectVedio(getSobotBaseActivity());
}
}
\ No newline at end of file
......@@ -37,6 +37,9 @@
<string name="sobot_memory_card_yongtu">You can send pictures, videos and files to describe the problem when you consult customer service and leave a message</string>
<string name="sobot_camera">Camera</string>
<string name="sobot_camera_yongtu">You can send photos and videos for help when consulting customer service and leaving a message</string>
<string name="sobot_microphone">Microphone</string>
<string name="sobot_microphone_yongtu">You can use voice to communicate quickly when consulting customer service and leaving messages</string>
<string name="app_request_code_500001">Customer already exists</string>
<string name="app_request_code_500002">Lead already exists</string>
......
......@@ -37,7 +37,8 @@
<string name="sobot_memory_card_yongtu">您可以在咨询客服和留言时,发送图片、视频、文件描述问题</string>
<string name="sobot_camera">相机</string>
<string name="sobot_camera_yongtu">您可以在咨询客服和留言时,发送拍摄的照片和视频获取帮助</string>
<string name="sobot_microphone">麦克风</string>
<string name="sobot_microphone_yongtu">您可以在咨询客服和留言时,使用语音快速沟通</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment