Using android's native Camera App to capture photos throws SecurityException

后端 未结 3 1257
梦如初夏
梦如初夏 2021-01-25 02:58

I am trying to take photo from android device\'s native Camera App. For that i create a file first and then attach its URI with the intent to capture image and write output in t

相关标签:
3条回答
  • 2021-01-25 03:31

    However, not all Android devices actually have these hardware features. So if your app requests the CAMERA permission, it's important that you also include the <uses-feature> tag in your manifest to declare whether or not this feature is actually required. For more information, see Google Play and feature-based filtering

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="your package" >
        <uses-permission android:name="android.permission.CAMERA"/>
        <uses-permission  android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-feature android:name="android.hardware.camera2.full" />
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name=".MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    </manifest>
    

    From Marshmallow, Dangerous permissions are:

    1. READ_CALENDAR
    2. WRITE_CALENDAR
    3. CAMERA
    4. READ_CONTACTS
    5. WRITE_CONTACTS
    6. GET_ACCOUNTS
    7. ACCESS_FINE_LOCATION
    8. ACCESS_COARSE_LOCATION
    9. RECORD_AUDIO
    10. READ_PHONE_STATE
    11. CALL_PHONE
    12. READ_CALL_LOG
    13. WRITE_CALL_LOG
    14. ADD_VOICEMAIL
    15. USE_SIP
    16. PROCESS_OUTGOING_CALLS
    17. BODY_SENSORS
    18. SEND_SMS
    19. RECEIVE_SMS
    20. READ_SMS
    21. RECEIVE_WAP_PUSH
    22. RECEIVE_MMS
    23. READ_EXTERNAL_STORAGE
    24. WRITE_EXTERNAL_STORAGE

    SO i think Permission may be required...

    0 讨论(0)
  • 2021-01-25 03:36

    The issue is the revoked permission ("with revoked permission android.permission.CAMERA"). Normally, you do not need permission, but if you ask for permission (say, in a previous build of your app), and the user revokes that permission, then you cannot use ACTION_IMAGE_CAPTURE.

    0 讨论(0)
  • 2021-01-25 03:40

    Add below lines in your Manifest.xml :

    <uses-feature
    android:name="android.hardware.camera.any"
    android:required="true" />
    
    <uses-feature
    android:name="android.hardware.camera.autofocus"
    android:required="false" />
    <uses-permission android:name="android.permission.CAMERA" />
    

    Please refer to this URL for more.

    0 讨论(0)
提交回复
热议问题