Fix media cannot be downloaded or shared (Android 10)

This commit is contained in:
Thomas 2023-02-05 16:50:08 +01:00
parent 6595af849e
commit cbed3f1ae1
7 changed files with 7 additions and 6 deletions

View File

@ -250,7 +250,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
int position = binding.mediaViewpager.getCurrentItem(); int position = binding.mediaViewpager.getCurrentItem();
Attachment attachment = attachments.get(position); Attachment attachment = attachments.get(position);
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= 23) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
if (ContextCompat.checkSelfPermission(MediaActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(MediaActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { if (ContextCompat.checkSelfPermission(MediaActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(MediaActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MediaActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE_MEDIA_SAVE); ActivityCompat.requestPermissions(MediaActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE_MEDIA_SAVE);
} else { } else {

View File

@ -265,7 +265,7 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList
.setClearViewsEnabled(true) .setClearViewsEnabled(true)
.setTransparencyEnabled(true) .setTransparencyEnabled(true)
.build(); .build();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
if (ContextCompat.checkSelfPermission(EditImageActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != if (ContextCompat.checkSelfPermission(EditImageActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) { PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(EditImageActivity.this, ActivityCompat.requestPermissions(EditImageActivity.this,

View File

@ -399,7 +399,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
* @param position - int position of the media in the message * @param position - int position of the media in the message
*/ */
private void pickupMedia(ComposeActivity.mediaType type, int position) { private void pickupMedia(ComposeActivity.mediaType type, int position) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) != if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) { PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions((Activity) context, ActivityCompat.requestPermissions((Activity) context,

View File

@ -154,7 +154,7 @@ public class FragmentSettingsCategories extends PreferenceFragmentCompat {
Preference pref_export_settings = findPreference(getString(R.string.pref_export_settings)); Preference pref_export_settings = findPreference(getString(R.string.pref_export_settings));
if (pref_export_settings != null) { if (pref_export_settings != null) {
pref_export_settings.setOnPreferenceClickListener(preference -> { pref_export_settings.setOnPreferenceClickListener(preference -> {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
permissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE); permissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE);
} else { } else {
try { try {

View File

@ -821,7 +821,7 @@ public class Helper {
public static void requestPermissionAndProceed(Activity activity, PermissionGranted permissionGranted) { public static void requestPermissionAndProceed(Activity activity, PermissionGranted permissionGranted) {
if (Build.VERSION.SDK_INT >= 23) { if (Build.VERSION.SDK_INT >= 23) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, app.fedilab.android.mastodon.helper.Helper.EXTERNAL_STORAGE_REQUEST_CODE_MEDIA_SAVE); ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, app.fedilab.android.mastodon.helper.Helper.EXTERNAL_STORAGE_REQUEST_CODE_MEDIA_SAVE);
} else { } else {

View File

@ -237,7 +237,7 @@ public class FragmentLoginMain extends Fragment {
} }
}); });
} else if (itemId == R.id.action_import_data) { } else if (itemId == R.id.action_import_data) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
permissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE); permissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE);
} else { } else {
proceed(); proceed();

View File

@ -12,4 +12,5 @@ Fixed:
- Fix a crash when replying - Fix a crash when replying
- Fix button size not changed - Fix button size not changed
- Forward tags in replies - Forward tags in replies
- Media cannot be downloaded or shared with Android 10
- Some crashes - Some crashes