Commit 3447e50a by 郭倩芳

相册选照片、视频权限提示

parent d89fd9a5
...@@ -12,7 +12,7 @@ task androidSourcesJar(type: Jar) { ...@@ -12,7 +12,7 @@ task androidSourcesJar(type: Jar) {
ext { ext {
PUBLISH_GROUP_ID = "com.sobot.library" //项目包名 PUBLISH_GROUP_ID = "com.sobot.library" //项目包名
PUBLISH_ARTIFACT_ID = 'widget_x' //项目名 PUBLISH_ARTIFACT_ID = 'widget_x' //项目名
PUBLISH_VERSION = '1.1.8' //版本号 PUBLISH_VERSION = '1.2.0' //版本号
} }
......
...@@ -12,10 +12,12 @@ import android.hardware.Camera; ...@@ -12,10 +12,12 @@ import android.hardware.Camera;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.LocaleList; import android.os.LocaleList;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.View; import android.view.View;
...@@ -26,6 +28,7 @@ import android.widget.LinearLayout; ...@@ -26,6 +28,7 @@ import android.widget.LinearLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import com.sobot.utils.SobotLogUtils;
import com.sobot.utils.SobotSharedPreferencesUtil; import com.sobot.utils.SobotSharedPreferencesUtil;
import com.sobot.utils.SobotSystemUtils; import com.sobot.utils.SobotSystemUtils;
import com.sobot.widget.R; import com.sobot.widget.R;
...@@ -513,6 +516,19 @@ public abstract class SobotBaseActivity extends FragmentActivity { ...@@ -513,6 +516,19 @@ public abstract class SobotBaseActivity extends FragmentActivity {
switch (requestCode) { switch (requestCode) {
case SobotBaseConstant.REQUEST_CODE_PICTURE: case SobotBaseConstant.REQUEST_CODE_PICTURE:
try { try {
//判断是否选择部分的权限
// SobotLogUtils.d("=====判断是否选择部分的权限=======");
for (int i = 0; i < grantResults.length; i++) {
if (permissions[i] != null && permissions[i].equals(Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED)) {
// SobotLogUtils.d("=====android 14权限===="+permissions[i].equals(Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED)+"====="+grantResults[i]);
if(grantResults[i] == PackageManager.PERMISSION_GRANTED){
if (permissionListener != null) {
permissionListener.onPermissionSuccessListener();
}
return;
}
}
}
for (int i = 0; i < grantResults.length; i++) { for (int i = 0; i < grantResults.length; i++) {
//判断权限的结果,如果有被拒绝,就return //判断权限的结果,如果有被拒绝,就return
if (grantResults[i] != PackageManager.PERMISSION_GRANTED) { if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
...@@ -548,7 +564,7 @@ public abstract class SobotBaseActivity extends FragmentActivity { ...@@ -548,7 +564,7 @@ public abstract class SobotBaseActivity extends FragmentActivity {
} }
} }
} else if (permissions[i] != null && permissions[i].equals(Manifest.permission.READ_MEDIA_IMAGES)) { } else if (permissions[i] != null && permissions[i].equals(Manifest.permission.READ_MEDIA_IMAGES)) {
permissionTitle = getResources().getString(R.string.sobot_no_write_external_storage_permission); permissionTitle = getResources().getString(R.string.sobot_no_record_images_permission);
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_MEDIA_IMAGES) && !SobotWidgetApi.getSwitchMarkStatus(SobotMarkConfig.SHOW_PERMISSION_TIPS_POP)) { 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)); 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 { } else {
...@@ -558,7 +574,7 @@ public abstract class SobotBaseActivity extends FragmentActivity { ...@@ -558,7 +574,7 @@ public abstract class SobotBaseActivity extends FragmentActivity {
} }
} }
} else if (permissions[i] != null && permissions[i].equals(Manifest.permission.READ_MEDIA_VIDEO)) { } else if (permissions[i] != null && permissions[i].equals(Manifest.permission.READ_MEDIA_VIDEO)) {
permissionTitle = getResources().getString(R.string.sobot_no_write_external_storage_permission); permissionTitle = getResources().getString(R.string.sobot_no_record_video_permission);
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_MEDIA_VIDEO) && !SobotWidgetApi.getSwitchMarkStatus(SobotMarkConfig.SHOW_PERMISSION_TIPS_POP)) { 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)); 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 { } else {
...@@ -568,9 +584,9 @@ public abstract class SobotBaseActivity extends FragmentActivity { ...@@ -568,9 +584,9 @@ public abstract class SobotBaseActivity extends FragmentActivity {
} }
} }
} else if (permissions[i] != null && permissions[i].equals(Manifest.permission.READ_MEDIA_AUDIO)) { } else if (permissions[i] != null && permissions[i].equals(Manifest.permission.READ_MEDIA_AUDIO)) {
permissionTitle = getResources().getString(R.string.sobot_no_write_external_storage_permission); permissionTitle = getResources().getString(R.string.sobot_no_record_audio_permission);
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_MEDIA_AUDIO) && !SobotWidgetApi.getSwitchMarkStatus(SobotMarkConfig.SHOW_PERMISSION_TIPS_POP)) { 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)); SobotToastUtil.showCustomLongToast(this, SobotSystemUtils.getAppName(this) + getResources().getString(R.string.sobot_want_use_your) + getString(R.string.sobot_microphone) + " , " + getString(R.string.sobot_microphone_yongtu));
} else { } else {
//调用权限失败 //调用权限失败
if (permissionListener != null) { if (permissionListener != null) {
...@@ -633,12 +649,9 @@ public abstract class SobotBaseActivity extends FragmentActivity { ...@@ -633,12 +649,9 @@ public abstract class SobotBaseActivity extends FragmentActivity {
return false; return false;
} }
} else { } else {
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_IMAGES) == PackageManager.PERMISSION_GRANTED 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_VIDEO) != PackageManager.PERMISSION_GRANTED
|| ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED) == PackageManager.PERMISSION_GRANTED
) { ) {
return true;
} else {
//申请:图片权限 视频权限 音频权限 //申请:图片权限 视频权限 音频权限
this.requestPermissions(new String[]{Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.READ_MEDIA_VIDEO, Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED}, SobotBaseConstant.REQUEST_CODE_PICTURE); this.requestPermissions(new String[]{Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.READ_MEDIA_VIDEO, Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED}, SobotBaseConstant.REQUEST_CODE_PICTURE);
return false; return false;
...@@ -689,11 +702,8 @@ public abstract class SobotBaseActivity extends FragmentActivity { ...@@ -689,11 +702,8 @@ public abstract class SobotBaseActivity extends FragmentActivity {
// SobotLogUtils.d("=======READ_MEDIA_IMAGES=====" + ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_IMAGES)+"===="+(ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_IMAGES) == PackageManager.PERMISSION_GRANTED)); // SobotLogUtils.d("=======READ_MEDIA_IMAGES=====" + ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_IMAGES)+"===="+(ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_IMAGES) == PackageManager.PERMISSION_GRANTED));
// SobotLogUtils.d("=======READ_MEDIA_VIDEO=====" + ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VIDEO)+"===="+(ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VIDEO) == PackageManager.PERMISSION_GRANTED)); // SobotLogUtils.d("=======READ_MEDIA_VIDEO=====" + ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VIDEO)+"===="+(ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VIDEO) == PackageManager.PERMISSION_GRANTED));
// SobotLogUtils.d("=======READ_MEDIA_VISUAL_USER_SELECTED=====" + ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED)+"===="+(ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED) == PackageManager.PERMISSION_GRANTED)); // SobotLogUtils.d("=======READ_MEDIA_VISUAL_USER_SELECTED=====" + ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED)+"===="+(ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED) == PackageManager.PERMISSION_GRANTED));
if (ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_IMAGES) == PackageManager.PERMISSION_GRANTED 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_VIDEO) != PackageManager.PERMISSION_GRANTED) {
|| ContextCompat.checkSelfPermission(getSobotBaseActivity(), Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED) == PackageManager.PERMISSION_GRANTED) {
return true;
} else {
return false; return false;
} }
} }
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
<string name="sobot_no_write_external_storage_permission">No write external storage permission</string> <string name="sobot_no_write_external_storage_permission">No write external storage permission</string>
<string name="sobot_no_record_audio_permission">Unable to record</string> <string name="sobot_no_record_audio_permission">Unable to record</string>
<string name="sobot_no_record_images_permission">No permission to obtain images</string>
<string name="sobot_no_record_video_permission">No video permission obtained</string>
<string name="sobot_no_camera_permission">No camera permission</string> <string name="sobot_no_camera_permission">No camera permission</string>
<string name="sobot_want_use_your"> want to visit yours </string> <string name="sobot_want_use_your"> want to visit yours </string>
<string name="sobot_memory_card">File</string> <string name="sobot_memory_card">File</string>
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
<string name="sobot_no_write_external_storage_permission">没有存储权限</string> <string name="sobot_no_write_external_storage_permission">没有存储权限</string>
<string name="sobot_no_record_audio_permission">没有麦克风权限</string> <string name="sobot_no_record_audio_permission">没有麦克风权限</string>
<string name="sobot_no_record_images_permission">没有读取图片权限</string>
<string name="sobot_no_record_video_permission">没有读取视频权限</string>
<string name="sobot_no_camera_permission">没有相机权限</string> <string name="sobot_no_camera_permission">没有相机权限</string>
<string name="sobot_want_use_your">想访问您的</string> <string name="sobot_want_use_your">想访问您的</string>
<string name="sobot_memory_card">文件</string> <string name="sobot_memory_card">文件</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