Commit 5df18524 by zhengnw@sobot.com

baseactivity 适配android13 权限

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