|
@@ -21,9 +21,37 @@ public class MainActivity extends AppCompatActivity {
|
|
public static boolean crashed = false;
|
|
public static boolean crashed = false;
|
|
|
|
|
|
private final static int REQUEST_FILESYSTEM_ACCESS_CODE = 101;
|
|
private final static int REQUEST_FILESYSTEM_ACCESS_CODE = 101;
|
|
|
|
+ private final AppCompatActivity mActivity = this;
|
|
|
|
|
|
- private void requestForPermissions() {
|
|
|
|
- ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_FILESYSTEM_ACCESS_CODE);
|
|
|
|
|
|
+ private void requestForPermissions(boolean exitIfRequestForbidden) {
|
|
|
|
+ if (ActivityCompat.shouldShowRequestPermissionRationale(mActivity, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
|
|
|
+ ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_FILESYSTEM_ACCESS_CODE);
|
|
|
|
+ } else {
|
|
|
|
+ if (exitIfRequestForbidden) {
|
|
|
|
+ System.exit(1);
|
|
|
|
+ } else {
|
|
|
|
+ alertUser();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void alertUser() {
|
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
+ builder.setMessage(R.string.toast_requestpermission);
|
|
|
|
+ builder.setCancelable(false);
|
|
|
|
+ builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
+ requestForPermissions(true);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
+ System.exit(1);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ builder.create().show();
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -34,22 +62,7 @@ public class MainActivity extends AppCompatActivity {
|
|
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
StartGame();
|
|
StartGame();
|
|
} else {
|
|
} else {
|
|
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
- builder.setMessage(R.string.toast_requestpermission);
|
|
|
|
- builder.setCancelable(false);
|
|
|
|
- builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
- @Override
|
|
|
|
- public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
- requestForPermissions();
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
|
|
|
- @Override
|
|
|
|
- public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
- System.exit(1);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- builder.create().show();
|
|
|
|
|
|
+ alertUser();
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -58,10 +71,11 @@ public class MainActivity extends AppCompatActivity {
|
|
@Override
|
|
@Override
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED)
|
|
|
|
|
|
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
|
StartGame();
|
|
StartGame();
|
|
- else
|
|
|
|
- requestForPermissions();
|
|
|
|
|
|
+ } else {
|
|
|
|
+ requestForPermissions(false);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public void StartGame() {
|
|
public void StartGame() {
|