Skip to content

Commit

Permalink
Remove READ_EXTERNAL_STORAGE permission and permission request logic
Browse files Browse the repository at this point in the history
  • Loading branch information
norkator committed Jun 7, 2021
1 parent 1c8da26 commit 1b0a283
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 36 deletions.
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<!-- Required Permissions -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
Expand Down
45 changes: 10 additions & 35 deletions app/src/main/java/com/nitramite/apcupsdmonitor/UpsEditor.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package com.nitramite.apcupsdmonitor;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
Expand All @@ -23,7 +19,6 @@
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import com.nitramite.ui.FileDialog;

Expand All @@ -33,10 +28,6 @@

public class UpsEditor extends AppCompatActivity {

// App camera permissions
private static final int READ_EXTERNAL_STORAGE_REQUEST_CODE = 2;
private final String permissionReadStorage = Manifest.permission.READ_EXTERNAL_STORAGE;

// Variables
private SharedPreferences sharedPreferences;
private String upsId = null;
Expand Down Expand Up @@ -159,17 +150,15 @@ public void onNothingSelected(AdapterView<?> parent) {

Button selectPrivateKeyLocationBtn = findViewById(R.id.selectPrivateKeyLocationBtn);
selectPrivateKeyLocationBtn.setOnClickListener(view -> {
if (hasPermissions(UpsEditor.this, new String[]{permissionReadStorage})) {
File mPath = new File(Environment.getExternalStorageDirectory() + "//DIR//");
final FileDialog fileDialog = new FileDialog(UpsEditor.this, mPath, "");
fileDialog.addFileListener(file -> {
Toast.makeText(UpsEditor.this, getString(R.string.path) + ": " + file.toString(), Toast.LENGTH_SHORT).show();
privateKeyLocationET.setText(file.toString());
});
fileDialog.showDialog();
} else {
ActivityCompat.requestPermissions(UpsEditor.this, new String[]{permissionReadStorage}, READ_EXTERNAL_STORAGE_REQUEST_CODE);
}

File mPath = new File(Environment.getExternalStorageDirectory() + "//DIR//");
final FileDialog fileDialog = new FileDialog(UpsEditor.this, mPath, "");
fileDialog.addFileListener(file -> {
Toast.makeText(UpsEditor.this, getString(R.string.path) + ": " + file.toString(), Toast.LENGTH_SHORT).show();
privateKeyLocationET.setText(file.toString());
});
fileDialog.showDialog();

});


Expand Down Expand Up @@ -217,21 +206,7 @@ public void onNothingSelected(AdapterView<?> parent) {
prefsEditor.apply();
});


} // End of onCreate();


// Check for required permissions
private static boolean hasPermissions(Context context, String[] permissions) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null) {
for (String permission : permissions) {
if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
}
return true;
}


}

0 comments on commit 1b0a283

Please sign in to comment.