Merge remote-tracking branch 'origin/dev2_aiSdk' into dev2_aiSdk

This commit is contained in:
董宏宇
2021-05-27 18:13:31 +08:00
2 changed files with 2 additions and 104 deletions

View File

@@ -12,8 +12,8 @@ ext {
commonIndependentAmapApiValue : "1c3fbc5f5e183619ffb1e7bc01e6751f",
compileSdkVersion : 28,
buildToolsVersion : "29.0.2",
minSdkVersion : 19,
targetSdkVersion : 22,
minSdkVersion : 22,
targetSdkVersion : 23,
]
dependencies = [
// androidx

View File

@@ -59,9 +59,7 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
super.onCreate(savedInstanceState);
DebugConfig.setNeedRequestUserInfo(true);
Log.d(TAG, "onCreate");
Log.d("liyz", "MainLauncherActivity onCreate ------->");
mServiceApis.getV2XListenerManager().registerIntentListener(MogoReceiver.ACTION_V2X_FRONT_WARNING, this);
// checkPermission();
}
@Override
@@ -261,104 +259,4 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis
}
}
private boolean isFirst = false;
private static final int MY_PERMISSION_REQUEST_CODE = 10000;
/**
* 检查是否有相应的权限
*/
private void checkPermission() {
boolean isAllGranted = checkPermissionAllGranted(
new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS,
Manifest.permission.ACCESS_FINE_LOCATION
}
);
Log.d("liyz", "MainLauncherActivity checkPermission -------> isAllGranted = " + isAllGranted);
if (isAllGranted) {
return;
}
/**
* 请求权限
*/
ActivityCompat.requestPermissions(
this,
new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS,
Manifest.permission.ACCESS_FINE_LOCATION
}, MY_PERMISSION_REQUEST_CODE);
}
/**
* 检查是否拥有指定的所有权限
*/
private boolean checkPermissionAllGranted(String[] permissions) {
for (String permission : permissions) {
if (ContextCompat.checkSelfPermission(getContext(), permission) != PackageManager.PERMISSION_GRANTED) {
// 只要有一个权限没有被授予, 则直接返回 false
return false;
}
}
return true;
}
/**
* 申请权限结果返回处理
*/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == MY_PERMISSION_REQUEST_CODE) {
boolean isAllGranted = true;
// 判断是否所有的权限都已经授予了
for (int grant : grantResults) {
Log.d("liyz", "grant =" + grant);
if (grant != PackageManager.PERMISSION_GRANTED) {
isAllGranted = false;
break;
}
}
Log.d("liyz", "onRequestPermissionsResult isAllGranted = " + isAllGranted);
if (isAllGranted) {
isFirst = false;
} else {
// 弹出对话框告诉用户需要权限的原因, 并引导用户去应用权限管理中手动打开权限按钮
if (!isFirst) {
openAppDetails();
isFirst = true;
}
}
}
}
/**
* 打开APP的详情设置
*/
private void openAppDetails() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("请在 “应用信息 -> 权限” 中授予权限");
builder.setPositiveButton("手动授权", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse("package:" + getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
startActivity(intent);
}
});
builder.setNegativeButton("取消", null);
builder.show();
}
}