Issue with media

This commit is contained in:
Thomas 2022-12-28 11:44:36 +01:00
parent e265078210
commit 20c031f39e
5 changed files with 62 additions and 27 deletions

View file

@ -27,6 +27,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.util.Log;
import android.view.Display; import android.view.Display;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -243,9 +244,19 @@ 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 (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 (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
ActivityCompat.requestPermissions(MediaActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE_MEDIA_SAVE); 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);
} else {
if (attachment.type.compareTo("image") == 0) {
MediaHelper.manageMove(MediaActivity.this, attachment.url, false);
} else {
MediaHelper.manageDownloadsNoPopup(MediaActivity.this, attachment.url);
downloadID = -1;
}
}
} else { } else {
Log.v(Helper.TAG, "ici");
if (attachment.type.compareTo("image") == 0) { if (attachment.type.compareTo("image") == 0) {
MediaHelper.manageMove(MediaActivity.this, attachment.url, false); MediaHelper.manageMove(MediaActivity.this, attachment.url, false);
} else { } else {

View file

@ -8,6 +8,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -252,7 +253,7 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList
} }
private void saveImage() { private void saveImage() {
if (requestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) { if (requestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) || Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
showLoading(getString(R.string.saving)); showLoading(getString(R.string.saving));
File file = new File(path); File file = new File(path);
try { try {
@ -263,13 +264,16 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList
.setClearViewsEnabled(true) .setClearViewsEnabled(true)
.setTransparencyEnabled(true) .setTransparencyEnabled(true)
.build(); .build();
if (ContextCompat.checkSelfPermission(EditImageActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
PackageManager.PERMISSION_GRANTED) { if (ContextCompat.checkSelfPermission(EditImageActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
ActivityCompat.requestPermissions(EditImageActivity.this, PackageManager.PERMISSION_GRANTED) {
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, ActivityCompat.requestPermissions(EditImageActivity.this,
STORE_REQUEST); new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
return; STORE_REQUEST);
return;
}
} }
mPhotoEditor.saveAsFile(file.getAbsolutePath(), saveSettings, new PhotoEditor.OnSaveListener() { mPhotoEditor.saveAsFile(file.getAbsolutePath(), saveSettings, new PhotoEditor.OnSaveListener() {
@Override @Override
public void onSuccess(@NonNull String imagePath) { public void onSuccess(@NonNull String imagePath) {

View file

@ -390,12 +390,14 @@ 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 (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) != if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
PackageManager.PERMISSION_GRANTED) { if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) !=
ActivityCompat.requestPermissions((Activity) context, PackageManager.PERMISSION_GRANTED) {
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, ActivityCompat.requestPermissions((Activity) context,
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE); new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
return; MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
return;
}
} }
Intent intent; Intent intent;
intent = new Intent(Intent.ACTION_GET_CONTENT); intent = new Intent(Intent.ACTION_GET_CONTENT);

View file

@ -27,6 +27,7 @@ import android.Manifest;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
@ -86,16 +87,7 @@ public class FragmentLoginMain extends Fragment {
permissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { permissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
if (isGranted) { if (isGranted) {
Intent openFileIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT); proceed();
openFileIntent.addCategory(Intent.CATEGORY_OPENABLE);
openFileIntent.setType("application/zip");
String[] mimeTypes = new String[]{"application/zip"};
openFileIntent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
//noinspection deprecation
startActivityForResult(
Intent.createChooser(
openFileIntent,
getString(R.string.load_settings)), PICK_IMPORT);
} else { } else {
ActivityCompat.requestPermissions(requireActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE); ActivityCompat.requestPermissions(requireActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE);
} }
@ -233,13 +225,30 @@ public class FragmentLoginMain extends Fragment {
} }
}); });
} else if (itemId == R.id.action_import_data) { } else if (itemId == R.id.action_import_data) {
permissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
permissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE);
} else {
proceed();
}
} }
return false; return false;
}); });
popupMenu.show(); popupMenu.show();
} }
private void proceed() {
Intent openFileIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
openFileIntent.addCategory(Intent.CATEGORY_OPENABLE);
openFileIntent.setType("application/zip");
String[] mimeTypes = new String[]{"application/zip"};
openFileIntent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
//noinspection deprecation
startActivityForResult(
Intent.createChooser(
openFileIntent,
getString(R.string.load_settings)), PICK_IMPORT);
}
private void retrievesClientId(String instance) { private void retrievesClientId(String instance) {
String oldInstance = instance; String oldInstance = instance;
if (!instance.startsWith("http://") && !instance.startsWith("https://")) { if (!instance.startsWith("http://") && !instance.startsWith("https://")) {

View file

@ -18,6 +18,7 @@ import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.webkit.URLUtil; import android.webkit.URLUtil;
import android.widget.Toast; import android.widget.Toast;
@ -135,7 +136,15 @@ 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 -> {
permissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
permissionLauncher.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE);
} else {
try {
ZipHelper.exportData(requireActivity());
} catch (IOException e) {
e.printStackTrace();
}
}
return false; return false;
}); });
} }