How get permission for camera in android Specifically Marshmallow

0 votes

Hello, I'm creating an Android app in Android Studio. I need the camera's consent in that situation. The AndroidManifest.xml file contains the code 

<uses-permission android:name="android.permission.CAMERA" />

With the exception of Marshmallow, it functions correctly on all versions of Android. How can I automatically receive camera permission? If that's not possible, how can I ask the user?

Nov 7 in Android by Edureka
• 10,880 points
30 views

1 answer to this question.

0 votes

To begin with, confirm that the user has given the permission:

if (ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA)
    == PackageManager.PERMISSION_DENIED)

Then, you might employ this to ask the user to:

ActivityCompat.requestPermissions(activity, new String[] {Manifest.permission.CAMERA}, requestCode);

Additionally, it will pop up in a dialogue in Marshmallow.

answered Nov 8 by Edureka
• 12,390 points

Related Questions In Android

0 votes
0 answers
0 votes
0 answers

How to get the device's IMEI/ESN programmatically in android?

I want to use the IMEI to ...READ MORE

Nov 16 in Android by Edureka
• 10,880 points
19 views
0 votes
0 answers

How to get current time and date in Android?

How can I get the current time ...READ MORE

Nov 22 in Android by Edureka
• 10,880 points
15 views
0 votes
0 answers

How do I get the current GPS location programmatically in Android?

I need to get my current location ...READ MORE

Nov 23 in Android by Ashwini
• 2,760 points
30 views
0 votes
1 answer

Running docker on Android

According to the documentation, the Android kernel is ...READ MORE

answered Aug 1, 2018 in Docker by Kalgi
• 52,350 points
3,027 views
0 votes
1 answer

Task Canceled Exception while invoking AWS Lambda

I'm guessing either the TaskCanceledException instance is ...READ MORE

answered Sep 19, 2018 in AWS by Priyaj
• 58,100 points
1,661 views
0 votes
1 answer

Is there a way to run Python on Android?

YES! An example via Matt Cutts via SL4A -- "here’s ...READ MORE

answered Sep 19, 2018 in Python by Priyaj
• 58,100 points
471 views
0 votes
1 answer

How can we get the current location in Android?

First you need to define a LocationListener to handle ...READ MORE

answered Sep 25, 2018 in Java by Parth
• 4,630 points
426 views
0 votes
1 answer
0 votes
1 answer

How to set my Activity as main activity in android?

The "intent-filter" in "AndroidManifest.xml" allows you to ...READ MORE

answered Nov 8 in Android by Edureka
• 12,390 points
36 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP