Skip to content

Commit

Permalink
fixed federicoiosue#944 : Ask for camera permission before launching …
Browse files Browse the repository at this point in the history
…gallery

Added Methods like
- checkCameraPermission
- requestCameraPermission

And requested permision from the user to take photos or record vedios
  • Loading branch information
akashs056 committed Dec 24, 2023
1 parent 3c36042 commit 14c3871
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions omniNotes/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.CAMERA"/>

<uses-feature
android:name="android.hardware.camera"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
Expand Down Expand Up @@ -109,6 +110,10 @@
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.util.Pair;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.FragmentTransaction;
Expand Down Expand Up @@ -200,7 +205,7 @@ public class DetailFragment extends BaseFragment implements OnReminderPickedList
private static final int CATEGORY = 5;
private static final int DETAIL = 6;
private static final int FILES = 7;

private static final int CAMERA_PERMISSION_REQUEST_CODE =8 ;
private FragmentDetailBinding binding;

boolean goBack = false;
Expand Down Expand Up @@ -2278,20 +2283,38 @@ private boolean checkWeakReferences() {
&& detailFragmentWeakReference.get() != null && noteTmpWeakReference.get() != null;
}
}

/**
* Manages clicks on attachment dialog
*/
private boolean checkCameraPermission() {
if (ContextCompat.checkSelfPermission(
requireActivity(),
Manifest.permission.CAMERA
) == PackageManager.PERMISSION_GRANTED) {
return true;
} else {
return false;
}
}
private void requestCameraPermission() {
requestPermissions(
new String[]{Manifest.permission.CAMERA},
CAMERA_PERMISSION_REQUEST_CODE
);
}
@SuppressLint("InlinedApi")
private class AttachmentOnClickListener implements OnClickListener {

@Override
public void onClick(View v) {

switch (v.getId()) {
// Photo from camera
case R.id.camera:
takePhoto();
if (!checkCameraPermission()) {
requestCameraPermission();
} else {
takePhoto();
}
break;
case R.id.recording:
if (!isRecording) {
Expand All @@ -2307,7 +2330,11 @@ public void onClick(View v) {
}
break;
case R.id.video:
takeVideo();
if (!checkCameraPermission()) {
requestCameraPermission();
} else {
takeVideo();
}
break;
case R.id.files:
startGetContentAction();
Expand Down

0 comments on commit 14c3871

Please sign in to comment.