Fix android r permission problem

pull/5/head
FongMi 4 years ago
parent 4a02c8a3b1
commit 7de7d9d8e4
  1. 4
      app/build.gradle
  2. 3
      app/src/main/AndroidManifest.xml
  3. 12
      app/src/main/java/com/fongmi/bear/ui/activity/SettingActivity.java

@ -44,8 +44,8 @@ dependencies {
implementation 'com.github.bassaer:materialdesigncolors:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.13.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'com.google.android.exoplayer:exoplayer:2.18.0'
implementation 'com.google.android.exoplayer:extension-rtmp:2.18.0'
implementation 'com.google.android.exoplayer:exoplayer:2.18.1'
implementation 'com.google.android.exoplayer:extension-rtmp:2.18.1'
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'org.greenrobot:eventbus:3.3.1'
implementation 'org.jsoup:jsoup:1.14.3'

@ -1,11 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.fongmi.bear">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage" />
<uses-feature
android:name="android.hardware.touchscreen"
@ -21,6 +23,7 @@
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"

@ -5,6 +5,9 @@ import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Environment;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.EditorInfo;
@ -36,7 +39,8 @@ public class SettingActivity extends BaseActivity {
activity.startActivityForResult(new Intent(activity, SettingActivity.class), 1000);
}
private final ActivityResultLauncher<String> permissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> loadConfig());
private final ActivityResultLauncher<String> launcherString = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> loadConfig());
private final ActivityResultLauncher<Intent> launcherIntent = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> loadConfig());
@Override
protected ViewBinding getBinding() {
@ -73,8 +77,10 @@ public class SettingActivity extends BaseActivity {
}
private void checkUrl() {
if (Prefers.getUrl().startsWith("file://") && ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
permissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE);
if (Prefers.getUrl().startsWith("file://") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !Environment.isExternalStorageManager()) {
launcherIntent.launch(new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION));
} else if (Prefers.getUrl().startsWith("file://") && Build.VERSION.SDK_INT < Build.VERSION_CODES.R && ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
launcherString.launch(Manifest.permission.READ_EXTERNAL_STORAGE);
} else {
loadConfig();
}

Loading…
Cancel
Save