parent
379c12a9d8
commit
a59884b319
|
@ -1,22 +1,21 @@
|
||||||
package com.tungsten.fcl.activity;
|
package com.tungsten.fcl.activity;
|
||||||
|
|
||||||
|
import static android.Manifest.permission.*;
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Intent;
|
import android.app.AlertDialog;
|
||||||
import android.content.SharedPreferences;
|
import android.content.*;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import com.tungsten.fcl.R;
|
import com.tungsten.fcl.R;
|
||||||
import com.tungsten.fcl.fragment.EulaFragment;
|
import com.tungsten.fcl.fragment.EulaFragment;
|
||||||
import com.tungsten.fcl.fragment.RuntimeFragment;
|
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.ResultListener;
|
||||||
import com.tungsten.fcllibrary.component.dialog.FCLAlertDialog;
|
import com.tungsten.fcllibrary.component.dialog.FCLAlertDialog;
|
||||||
import com.tungsten.fcllibrary.component.theme.ThemeEngine;
|
import com.tungsten.fcllibrary.component.theme.ThemeEngine;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.*;
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
@SuppressLint("CustomSplashScreen")
|
@SuppressLint("CustomSplashScreen")
|
||||||
public class SplashActivity extends FCLActivity {
|
public class SplashActivity extends FCLActivity {
|
||||||
|
@ -71,10 +67,19 @@ public class SplashActivity extends FCLActivity {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} 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();
|
init();
|
||||||
} else {
|
} 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) {
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
init();
|
init();
|
||||||
} else {
|
} else {
|
||||||
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
if (!ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) || !ActivityCompat.shouldShowRequestPermissionRationale(this, READ_EXTERNAL_STORAGE)) {
|
||||||
recheckPermission();
|
// 用户勾选了“始终拒绝”
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,11 @@
|
||||||
<string name="oauth_api_key" translatable="false">null</string>
|
<string name="oauth_api_key" translatable="false">null</string>
|
||||||
|
|
||||||
<string name="splash_permission_msg">Sem permissão de armazenamento, por favor conceda a permissão ao Fold Craft Launcher.</string>
|
<string name="splash_permission_msg">Sem permissão de armazenamento, por favor conceda a permissão ao Fold Craft Launcher.</string>
|
||||||
|
<string name="splash_permission_grant">Grant</string>
|
||||||
|
<string name="splash_permission_title">Permission to store needed</string>
|
||||||
|
<string name="splash_permission_close">Close the app</string>
|
||||||
|
<string name="splash_permission_settings">Settings</string>
|
||||||
|
<string name="splash_permission_settings_msg">You have chosen "Never Allow." Please manually grant storage permissions in settings.</string>
|
||||||
|
|
||||||
<string name="splash_title">Bem-vindo ao Fold Craft Launcher</string>
|
<string name="splash_title">Bem-vindo ao Fold Craft Launcher</string>
|
||||||
<string name="splash_eula_error">Não foi possível acessar o EULA, por favor verifique a sua conexão.</string>
|
<string name="splash_eula_error">Não foi possível acessar o EULA, por favor verifique a sua conexão.</string>
|
||||||
|
|
|
@ -4,6 +4,11 @@
|
||||||
<string name="oauth_api_key" translatable="false">null</string>
|
<string name="oauth_api_key" translatable="false">null</string>
|
||||||
|
|
||||||
<string name="splash_permission_msg">Нет доступа к хранилищу, предоствьте разрешение приложению Fold Craft Launcher в настройках.</string>
|
<string name="splash_permission_msg">Нет доступа к хранилищу, предоствьте разрешение приложению Fold Craft Launcher в настройках.</string>
|
||||||
|
<string name="splash_permission_grant">Grant</string>
|
||||||
|
<string name="splash_permission_title">Permission to store needed</string>
|
||||||
|
<string name="splash_permission_close">Close the app</string>
|
||||||
|
<string name="splash_permission_settings">Settings</string>
|
||||||
|
<string name="splash_permission_settings_msg">You have chosen "Never Allow." Please manually grant storage permissions in settings.</string>
|
||||||
|
|
||||||
<string name="splash_title">Добро пожаловать в Fold Craft Launcher.</string>
|
<string name="splash_title">Добро пожаловать в Fold Craft Launcher.</string>
|
||||||
<string name="splash_eula_error">Не удалось подтвердить наличие лицензии, из за проблем с соединением.</string>
|
<string name="splash_eula_error">Не удалось подтвердить наличие лицензии, из за проблем с соединением.</string>
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="splash_permission_msg">没有存储权限,请授予 Fold Craft Launcher 权限。</string>
|
<string name="splash_permission_msg">没有存储权限,请授予 Fold Craft Launcher 权限。</string>
|
||||||
|
<string name="splash_permission_grant">授予</string>
|
||||||
|
<string name="splash_permission_title">需要存储权限</string>
|
||||||
|
<string name="splash_permission_close">关闭应用</string>
|
||||||
|
<string name="splash_permission_settings">去设置</string>
|
||||||
|
<string name="splash_permission_settings_msg">您已选择永不授权,请在设置中手动授予存储权限。</string>
|
||||||
|
|
||||||
<string name="splash_title">欢迎使用 Fold Craft Launcher</string>
|
<string name="splash_title">欢迎使用 Fold Craft Launcher</string>
|
||||||
<string name="splash_eula_error">无法获取用户协议,请检查网络。</string>
|
<string name="splash_eula_error">无法获取用户协议,请检查网络。</string>
|
||||||
|
|
|
@ -4,6 +4,11 @@
|
||||||
<string name="oauth_api_key" translatable="false">null</string>
|
<string name="oauth_api_key" translatable="false">null</string>
|
||||||
|
|
||||||
<string name="splash_permission_msg">No storage permission, please grant Fold Craft Launcher the permission.</string>
|
<string name="splash_permission_msg">No storage permission, please grant Fold Craft Launcher the permission.</string>
|
||||||
|
<string name="splash_permission_grant">Grant</string>
|
||||||
|
<string name="splash_permission_title">Permission to store needed</string>
|
||||||
|
<string name="splash_permission_close">Close the app</string>
|
||||||
|
<string name="splash_permission_settings">Settings</string>
|
||||||
|
<string name="splash_permission_settings_msg">You have chosen "Never Allow" Please manually grant storage permissions in settings.</string>
|
||||||
|
|
||||||
<string name="splash_title">Welcome to Fold Craft Launcher</string>
|
<string name="splash_title">Welcome to Fold Craft Launcher</string>
|
||||||
<string name="splash_eula_error">Cannot get EULA, please check the network.</string>
|
<string name="splash_eula_error">Cannot get EULA, please check the network.</string>
|
||||||
|
|
Loading…
Reference in New Issue