fix: 修改ocr申请权限错误的问题

This commit is contained in:
xiaoyan 2023-04-18 13:49:12 +08:00
parent 6a5b6a5f19
commit 26f6627be0
8 changed files with 162 additions and 44 deletions

View File

@ -2,6 +2,26 @@ plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'org.sonarqube'
}
sonarqube {
properties {
//Sonar服务器地址
property "sonar.host.url", "http://10.130.14.162:9000/"
//Token模式
// property "sonar.login","TRD2022"
//
property "sonar.login","TRD2022"
property "sonar.password","TRD2022"
property "sonar.sourceEncoding", "UTF-8"
property "sonar.projectKey", "Android_DuoApp"
property "sonar.projectName", project.name
//(APP模块下面的java包里面的全部)
property "sonar.sources", "src/main/java"
property "sonar.projectVersion", project.version
}
}
//apply plugin: 'com.android.application'
//apply plugin: 'kotlin-android'
@ -17,8 +37,8 @@ android {
applicationId "com.navinfo.outdoor"
minSdkVersion 24
targetSdkVersion 30
versionCode 50
versionName "8.230406-测试版"
versionCode 52
versionName "8.230418-正式环境-测试版"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
@ -46,8 +66,8 @@ android {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
ndkVersion '21.3.6528147'
packagingOptions {
@ -155,7 +175,7 @@ dependencies {
// implementation 'com.tencent.map.geolocation:TencentLocationSdk-openplatform:7.4.9'
// https://github.com/getActivity/XXPermissions
implementation 'com.github.getActivity:XXPermissions:11.6'
implementation 'com.github.getActivity:XXPermissions:18.0'
//room
def room_version = "2.2.0-alpha01"

View File

@ -219,6 +219,11 @@
android:name="com.umeng.message.UmengMessageIntentReceiverService"
android:exported="false"
tools:replace="android:exported" />
<!-- 告知 XXPermissions 当前项目已经适配了分区存储特性 -->
<meta-data
android:name="ScopedStorage"
android:value="true" />
</application>
</manifest>

View File

@ -127,13 +127,13 @@ public class MainActivity extends BaseActivity {
// 申请多个权限
//.permission(Permission.Group.CALENDAR)
// 申请读写外部存储卡
.permission(Permission.MANAGE_EXTERNAL_STORAGE /*, Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE*/)
.permission(/*Permission.MANAGE_EXTERNAL_STORAGE,*/ Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE)
// 申请相机权限
.permission(Permission.CAMERA)
.permission(Permission.REQUEST_INSTALL_PACKAGES)
// 位置权限
.permission(Permission.ACCESS_FINE_LOCATION)
.permission(Permission.ACCESS_MEDIA_LOCATION)
// .permission(Permission.ACCESS_MEDIA_LOCATION)
//.permission(Permission.ACCESS_BACKGROUND_LOCATION)
.permission(Permission.ACCESS_COARSE_LOCATION)
//读写权限

View File

@ -1,12 +1,17 @@
package com.navinfo.outdoor.base;
import android.Manifest;
import android.app.Activity;
import android.app.Application;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
@ -18,10 +23,14 @@ import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.PermissionChecker;
import com.baidu.ai.edge.core.base.Consts;
import com.github.lazylibrary.util.StringUtils;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.navinfo.outdoor.R;
@ -59,6 +68,7 @@ public abstract class BaseActivity extends AppCompatActivity {
initView();
initData();
initListener();
requestPermission();
if (!EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().register(this);
}
@ -177,4 +187,83 @@ public abstract class BaseActivity extends AppCompatActivity {
startActivityForResult(intent, 0);
}
}
private static final int REQUEST_PERMISSION = 1;
protected boolean allPermissionsGranted;
private void requestPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
String[] permissions = new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE,
};
allPermissionsGranted = true;
for (String perm : permissions) {
if ((PermissionChecker.checkSelfPermission(this, perm) != PermissionChecker.PERMISSION_GRANTED)) {
allPermissionsGranted = false;
break;
}
}
if (!allPermissionsGranted) {
ActivityCompat.requestPermissions(BaseActivity.this, permissions, REQUEST_PERMISSION);
} else {
requestAllFilesAccess();
}
} else {
allPermissionsGranted = true;
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_PERMISSION) {
allPermissionsGranted = true;
for (int grantRes : grantResults) {
if (grantRes != PackageManager.PERMISSION_GRANTED) {
allPermissionsGranted = false;
break;
}
}
if (allPermissionsGranted) {
requestAllFilesAccess();
}
}
}
/**
* Android 11 跳转到设置获取SD卡根目录写入权限
*/
private void requestAllFilesAccess() {
if (!Consts.AUTH_REQUIRE_SDCARD) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !Environment.isExternalStorageManager()) {
allPermissionsGranted = false;
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(BaseActivity.this,
R.style.Theme_AppCompat_Light_Dialog_Alert);
alertBuilder.setMessage("需授权访问SD卡文件");
alertBuilder.setCancelable(false);
alertBuilder.setPositiveButton("去设置", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
alertBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertBuilder.show();
}
}
}

View File

@ -1620,41 +1620,43 @@ public class TreasureFragment extends BaseFragment implements View.OnClickListen
// 5 用户给予权限进行相应操作
// 6 用户没有给予权限 作出相应提示
// 7 某些5.0权限的手机执行相应操作
XXPermissions.with(this)
// 位置权限
.permission(Permission.ACCESS_COARSE_LOCATION)
.permission(Permission.ACCESS_FINE_LOCATION)
.permission(Permission.ACCESS_MEDIA_LOCATION)
//.permission(Permission.ACCESS_BACKGROUND_LOCATION)
.request(new OnPermissionCallback() {
@Override
public void onGranted(List<String> permissions, boolean all) {
if (all) {
//建立定位
initLocation();
} else {
dismissLoadingDialog();
ToastUtils.Message(getActivity(), "申请权限失败");
}
}
@Override
public void onDenied(List<String> permissions, boolean never) {
dismissLoadingDialog();
if (never) {
DialogSettings.style = DialogSettings.STYLE.STYLE_IOS;
DialogSettings.cancelable = false;
MessageDialog.show((AppCompatActivity) requireActivity(), "提示", permissions.toString() + " 被永久拒绝授权,请手动授予定位权限,", "确定").setOkButton(new OnDialogButtonClickListener() {
@Override
public boolean onClick(BaseDialog baseDialog, View v) {
XXPermissions.startPermissionActivity(requireActivity(), permissions);
getActivity().finish();
return false;
}
});
}
}
});
//建立定位
initLocation();
// XXPermissions.with(this)
// // 位置权限
// .permission(Permission.ACCESS_COARSE_LOCATION)
// .permission(Permission.ACCESS_FINE_LOCATION)
//// .permission(Permission.ACCESS_MEDIA_LOCATION)
// //.permission(Permission.ACCESS_BACKGROUND_LOCATION)
// .request(new OnPermissionCallback() {
// @Override
// public void onGranted(List<String> permissions, boolean all) {
// if (all) {
// //建立定位
// initLocation();
// } else {
// dismissLoadingDialog();
// ToastUtils.Message(getActivity(), "申请权限失败");
// }
// }
//
// @Override
// public void onDenied(List<String> permissions, boolean never) {
// dismissLoadingDialog();
// if (never) {
// DialogSettings.style = DialogSettings.STYLE.STYLE_IOS;
// DialogSettings.cancelable = false;
// MessageDialog.show((AppCompatActivity) requireActivity(), "提示", permissions.toString() + " 被永久拒绝授权,请手动授予定位权限,", "确定").setOkButton(new OnDialogButtonClickListener() {
// @Override
// public boolean onClick(BaseDialog baseDialog, View v) {
// XXPermissions.startPermissionActivity(requireActivity(), permissions);
// getActivity().finish();
// return false;
// }
// });
// }
// }
// });
}
/*设置定位图标样式*/

View File

@ -3,8 +3,8 @@ package com.navinfo.outdoor.http;
public class HttpInterface {
// public static final String IP = "http://172.23.138.133:9999/m4";//测试接口-IP
public static final String IP0 = "http://dtxbmaps.navinfo.com/dtxb/dev/m4";//开发接口-外网
public static final String IP = "http://dtxbmaps.navinfo.com/dtxb/test/m4";//测试接口-外网
public static final String IP2 = "http://dtxbmaps.navinfo.com/dtxb/m4";//正式接口
public static final String IP1 = "http://dtxbmaps.navinfo.com/dtxb/test/m4";//测试接口-外网
public static final String IP = "http://dtxbmaps.navinfo.com/dtxb/m4";//正式接口
public static final String USER_PATH = "/user/";//我的
public static final String MSG_LIST_PATH = "/msgList/";//发现
public static final String USER_LOGIN_PATH = "/userlogin/";//登录

View File

@ -29,6 +29,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:7.0.0'
//kotlin支持
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7'
}
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View File

@ -22,3 +22,4 @@ systemProp.https.proxyPort=1080
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
android.injected.testOnly=false
org.gradle.java.home = C:\\Program Files\\OpenJDK\\jdk-11.0.15.10-hotspot