|
11 | 11 | import android.content.ContentUris; |
12 | 12 | import android.content.Context; |
13 | 13 | import android.content.Intent; |
14 | | -import android.content.IntentSender; |
15 | 14 | import android.content.pm.PackageManager; |
16 | 15 | import android.database.Cursor; |
17 | 16 | import android.database.sqlite.SQLiteException; |
|
38 | 37 | import androidx.annotation.NonNull; |
39 | 38 | import androidx.annotation.Nullable; |
40 | 39 | import androidx.cardview.widget.CardView; |
| 40 | +import androidx.core.content.ContextCompat; |
41 | 41 | import androidx.core.content.FileProvider; |
42 | 42 | import androidx.lifecycle.AndroidViewModel; |
43 | 43 | import androidx.lifecycle.MutableLiveData; |
@@ -172,6 +172,14 @@ public Intent createIntent(@NonNull Context context, @NonNull Uri input) { |
172 | 172 | .putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); |
173 | 173 | } |
174 | 174 | }, cameraResultCallback); |
| 175 | + |
| 176 | + private Runnable cameraPermissionsCallback = null; |
| 177 | + private final ActivityResultLauncher<String> requestCameraPermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), granted -> { |
| 178 | + if(granted && cameraPermissionsCallback != null) { |
| 179 | + cameraPermissionsCallback.run(); |
| 180 | + } |
| 181 | + }); |
| 182 | + |
175 | 183 | private final ActivityResultLauncher<Intent> mediaSelectorLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> { |
176 | 184 | if(result.getResultCode() != Activity.RESULT_OK) return; |
177 | 185 |
|
@@ -688,6 +696,13 @@ private void setSystemPickerBubbleState(CardView view, boolean bubble, int tileS |
688 | 696 | * @param video Whether to capture a video instead of a picture |
689 | 697 | */ |
690 | 698 | private void requestCamera(boolean video) { |
| 699 | + //Check if we need permission |
| 700 | + if(ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { |
| 701 | + cameraPermissionsCallback = () -> requestCamera(video); |
| 702 | + requestCameraPermissionLauncher.launch(Manifest.permission.CAMERA); |
| 703 | + return; |
| 704 | + } |
| 705 | + |
691 | 706 | //Finding a free file |
692 | 707 | File targetFile = AttachmentStorageHelper.prepareContentFile(requireContext(), AttachmentStorageHelper.dirNameDraftPrepare, video ? FileNameConstants.videoName : FileNameConstants.pictureName); |
693 | 708 | viewModel.targetFileIntent = targetFile; |
|
0 commit comments