Разрешение запроса в возврате фрагмента всегда ложно ⇐ JAVA
Разрешение запроса в возврате фрагмента всегда ложно
My goal is to obtain permission to access the gallery and take an image from a fragment. This is my code
binding.memoryImage.setOnClickListener(v -> { try { if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { requestPermissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE); } else { openGallery(); } } catch (Exception e) { e.printStackTrace(); } }); private void openGallery() { Intent iGallery = new Intent(Intent.ACTION_PICK); iGallery.setType("image/*"); iGallery.setData(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); folderResult.launch(iGallery); } private ActivityResultLauncher requestPermissionLauncher = registerForActivityResult( new ActivityResultContracts.RequestPermission(), result -> { if (result) { openGallery(); } else { Toast.makeText(getContext(), "Permission denied", Toast.LENGTH_SHORT).show(); } } ); ActivityResultLauncher folderResult = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback() { @Override public void onActivityResult(ActivityResult result) { if (result.getResultCode() == Activity.RESULT_OK) { imageURI = result.getData().getData(); binding.memoryImage.setImageURI(imageURI); } } }); The problem is that result il always false. Whats wrong?
Источник: https://stackoverflow.com/questions/780 ... ways-false
My goal is to obtain permission to access the gallery and take an image from a fragment. This is my code
binding.memoryImage.setOnClickListener(v -> { try { if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { requestPermissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE); } else { openGallery(); } } catch (Exception e) { e.printStackTrace(); } }); private void openGallery() { Intent iGallery = new Intent(Intent.ACTION_PICK); iGallery.setType("image/*"); iGallery.setData(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); folderResult.launch(iGallery); } private ActivityResultLauncher requestPermissionLauncher = registerForActivityResult( new ActivityResultContracts.RequestPermission(), result -> { if (result) { openGallery(); } else { Toast.makeText(getContext(), "Permission denied", Toast.LENGTH_SHORT).show(); } } ); ActivityResultLauncher folderResult = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback() { @Override public void onActivityResult(ActivityResult result) { if (result.getResultCode() == Activity.RESULT_OK) { imageURI = result.getData().getData(); binding.memoryImage.setImageURI(imageURI); } } }); The problem is that result il always false. Whats wrong?
Источник: https://stackoverflow.com/questions/780 ... ways-false
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Не получено количество страниц при активности из адаптера фрагмента и класса фрагмента
Anonymous » » в форуме Android - 0 Ответы
- 20 Просмотры
-
Последнее сообщение Anonymous
-