diff --git a/FCL/src/main/java/com/tungsten/fcl/activity/SplashActivity.java b/FCL/src/main/java/com/tungsten/fcl/activity/SplashActivity.java index eb062212..5fe62972 100644 --- a/FCL/src/main/java/com/tungsten/fcl/activity/SplashActivity.java +++ b/FCL/src/main/java/com/tungsten/fcl/activity/SplashActivity.java @@ -1,22 +1,21 @@ package com.tungsten.fcl.activity; +import static android.Manifest.permission.*; import android.Manifest; import android.annotation.SuppressLint; -import android.content.Intent; -import android.content.SharedPreferences; +import android.app.AlertDialog; +import android.content.*; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.provider.Settings; - import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; - import com.tungsten.fcl.R; import com.tungsten.fcl.fragment.EulaFragment; import com.tungsten.fcl.fragment.RuntimeFragment; @@ -28,11 +27,8 @@ import com.tungsten.fcllibrary.component.FCLActivity; import com.tungsten.fcllibrary.component.ResultListener; import com.tungsten.fcllibrary.component.dialog.FCLAlertDialog; import com.tungsten.fcllibrary.component.theme.ThemeEngine; - -import java.io.File; import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; +import java.nio.file.*; @SuppressLint("CustomSplashScreen") public class SplashActivity extends FCLActivity { @@ -71,10 +67,19 @@ public class SplashActivity extends FCLActivity { }); } } else { - if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + if (ActivityCompat.checkSelfPermission(this, READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(this, WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { init(); } else { - ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, RequestCodes.PERMISSION_REQUEST_CODE); + if (ActivityCompat.shouldShowRequestPermissionRationale(this, WRITE_EXTERNAL_STORAGE) || ActivityCompat.shouldShowRequestPermissionRationale(this, READ_EXTERNAL_STORAGE)) { + // 若用户第一次拒绝了授予,那么将会弹窗提醒用户为什么需要该权限 + enableAlertDialog((dialog, which) -> { + ActivityCompat.requestPermissions(this, new String[]{WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE}, RequestCodes.PERMISSION_REQUEST_CODE); + dialog.dismiss(); + }, getString(R.string.splash_permission_title), getString(R.string.splash_permission_msg), getString(R.string.splash_permission_grant), getString(R.string.splash_permission_close)); + } else { + // 没有勾选始终拒绝的化则继续请求权限 + ActivityCompat.requestPermissions(this, new String[]{WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE}, RequestCodes.PERMISSION_REQUEST_CODE); + } } } } @@ -136,10 +141,38 @@ public class SplashActivity extends FCLActivity { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { init(); } else { - if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - recheckPermission(); + if (!ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) || !ActivityCompat.shouldShowRequestPermissionRationale(this, READ_EXTERNAL_STORAGE)) { + // 用户勾选了“始终拒绝” + enableAlertDialog((dialog, which) -> { + Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); + Uri uri = Uri.fromParts("package", getPackageName(), null); + intent.setData(uri); + ResultListener.startActivityForResult(this, intent, RequestCodes.PERMISSION_REQUEST_CODE, (requestCode1, resultCode, data) -> { + if (requestCode1 == RequestCodes.PERMISSION_REQUEST_CODE) { + if (ActivityCompat.checkSelfPermission(this, READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(this, WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) init(); + else onRequestPermissionsResult(requestCode1, permissions, grantResults); + + } + }); + + dialog.dismiss(); + }, getString(R.string.splash_permission_title), getString(R.string.splash_permission_settings_msg), getString(R.string.splash_permission_settings), getString(R.string.splash_permission_close)); + } else { + // 用户只是拒绝了权限 + checkPermission(); } } } } + + private void enableAlertDialog(DialogInterface.OnClickListener positiveButtonEvent, String... strings) { + new AlertDialog.Builder(this) + .setTitle(String.valueOf(strings[0])) + .setMessage(String.valueOf(strings[1])) + .setPositiveButton(String.valueOf(strings[2]), positiveButtonEvent) + .setNegativeButton(String.valueOf(strings[3]), (dialog, which) -> System.exit(0)) + .setCancelable(false) + .create() + .show(); + } } diff --git a/FCL/src/main/res/values-pt-rBR/strings.xml b/FCL/src/main/res/values-pt-rBR/strings.xml index 940b8457..d88615ba 100644 --- a/FCL/src/main/res/values-pt-rBR/strings.xml +++ b/FCL/src/main/res/values-pt-rBR/strings.xml @@ -4,6 +4,11 @@ null Sem permissão de armazenamento, por favor conceda a permissão ao Fold Craft Launcher. + Grant + Permission to store needed + Close the app + Settings + You have chosen "Never Allow." Please manually grant storage permissions in settings. Bem-vindo ao Fold Craft Launcher Não foi possível acessar o EULA, por favor verifique a sua conexão. diff --git a/FCL/src/main/res/values-ru/strings.xml b/FCL/src/main/res/values-ru/strings.xml index af65190b..0c436a43 100644 --- a/FCL/src/main/res/values-ru/strings.xml +++ b/FCL/src/main/res/values-ru/strings.xml @@ -4,6 +4,11 @@ null Нет доступа к хранилищу, предоствьте разрешение приложению Fold Craft Launcher в настройках. + Grant + Permission to store needed + Close the app + Settings + You have chosen "Never Allow." Please manually grant storage permissions in settings. Добро пожаловать в Fold Craft Launcher. Не удалось подтвердить наличие лицензии, из за проблем с соединением. diff --git a/FCL/src/main/res/values-zh/strings.xml b/FCL/src/main/res/values-zh/strings.xml index 9712be51..800e3304 100644 --- a/FCL/src/main/res/values-zh/strings.xml +++ b/FCL/src/main/res/values-zh/strings.xml @@ -1,6 +1,11 @@ 没有存储权限,请授予 Fold Craft Launcher 权限。 + 授予 + 需要存储权限 + 关闭应用 + 去设置 + 您已选择永不授权,请在设置中手动授予存储权限。 欢迎使用 Fold Craft Launcher 无法获取用户协议,请检查网络。 diff --git a/FCL/src/main/res/values/strings.xml b/FCL/src/main/res/values/strings.xml index 7df1f544..fc61ab17 100644 --- a/FCL/src/main/res/values/strings.xml +++ b/FCL/src/main/res/values/strings.xml @@ -4,6 +4,11 @@ null No storage permission, please grant Fold Craft Launcher the permission. + Grant + Permission to store needed + Close the app + Settings + You have chosen "Never Allow" Please manually grant storage permissions in settings. Welcome to Fold Craft Launcher Cannot get EULA, please check the network.