|
18 | 18 |
|
19 | 19 | import android.Manifest; |
20 | 20 | import android.content.Context; |
| 21 | +import android.content.Intent; |
21 | 22 | import android.content.SharedPreferences; |
| 23 | +import android.net.Uri; |
22 | 24 | import android.os.Build; |
23 | 25 | import android.os.Bundle; |
| 26 | +import android.os.Environment; |
| 27 | +import android.provider.Settings; |
24 | 28 | import android.view.View; |
25 | 29 |
|
26 | 30 | import androidx.fragment.app.Fragment; |
@@ -78,6 +82,12 @@ protected void onStart() { |
78 | 82 | super.onStart(); //called here because otherwise the onStart of the DownloadFragment is called before this onStart, and this could cause problems. |
79 | 83 | } |
80 | 84 |
|
| 85 | + @Override |
| 86 | + protected void onResume() { |
| 87 | + super.onResume(); |
| 88 | + checkAllFilesPermission(); //todo: remove before the final release |
| 89 | + } |
| 90 | + |
81 | 91 | @Override |
82 | 92 | protected void onStop() { |
83 | 93 | super.onStop(); |
@@ -151,6 +161,27 @@ public void onBackPressed() { |
151 | 161 | } |
152 | 162 | super.onBackPressed(); |
153 | 163 | } |
| 164 | + |
| 165 | + //todo: remove before the final release |
| 166 | + private void checkAllFilesPermission() { |
| 167 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { |
| 168 | + if (!Environment.isExternalStorageManager()) { |
| 169 | + requestAllFilesPermission(); |
| 170 | + } |
| 171 | + } |
| 172 | + } |
| 173 | + |
| 174 | + //todo: remove before the final release |
| 175 | + private void requestAllFilesPermission() { |
| 176 | + try { |
| 177 | + Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION); |
| 178 | + intent.setData(Uri.parse("package:" + getPackageName())); |
| 179 | + startActivityForResult(intent, 100); |
| 180 | + } catch (Exception e) { |
| 181 | + Intent intent = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION); |
| 182 | + startActivityForResult(intent, 100); |
| 183 | + } |
| 184 | + } |
154 | 185 | } |
155 | 186 |
|
156 | 187 |
|
0 commit comments