简体   繁体   中英

camera permission is not active on sumsung galaxy s6 android V.6

My app cant open front camera on galaxy s6 i dont know why pls help! In manifest i already add this. Manifest :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lenovo.somsong">
<!-- ขออนุญาติเปิดกล้อง -->
<uses-permission android:name="android.permission.CAMERA" />
<!-- ขออนุญาติใช้ที่จัดเก็ฐข้อมูล -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<!-- auto focus -->
<uses-feature android:name="android.hardware.camera.autofocus" />
<!--code ที่ใช้ในการ detcet ใบหน้า-->
<meta-data
    android:name="com.google.android.gms.vision.DEPENDENCIES"
    android:value="face" />
<!--รูปของ application -->
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name=".Home"
       >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <!--code เพื่อเปิดไปยังหน้าต่างๆ ทั้งหมด 19 หน้า เป็นการ run activity -->
    <activity android:name=".Ssreccom"/>
    <activity android:name=".Pop"/>
    <activity android:name=".Face"/>
    <activity android:name=".Kom"/>
    <activity android:name=".Ssdesign"/>
    <activity android:name=".Derectang"/>
    <activity android:name=".Popwo"/>
    <activity android:name=".Popman"/>
    <activity android:name=".Diamond"/>
    <activity android:name=".Rec"/>
    <activity android:name=".Re"/>
    <activity android:name=".Dere"/>
    <activity android:name=".Myss"/>
    <activity android:name=".Camm1"/>
    <activity android:name=".Dekom"/>
    <activity android:name=".Camw1"/>
    <activity android:name=".Dedai"/>
    <activity android:name=".Tryss"/>
</application>

So when i run app on S6 android v6 its cant open front camera at all , but on another android version 4-5 is fine. what should i do ?

For android v.6 permission form mamifest not enough ....

On all versions of Android, your app needs to declare both the normal and the dangerous permissions it needs in its app manifest, as described in Declaring Permissions. However, the effect of that declaration is different depending on the system version and your app's target SDK level:

  • If the device is running Android 5.1 or lower, or your app's target SDK is 22 or lower: If you list a dangerous permission in your manifest, the user has to grant the permission when they install the app; if they do not grant the permission, the system does not install the app at all.

  • If the device is running Android 6.0 or higher, and your app's target SDK is 23 or higher: The app has to list the permissions in the manifest, and it must request each dangerous permission it needs while the app is running. The user can grant or deny each permission, and the app can continue to run with limited capabilities even if the user denies a permission request.

So you need to get permission from the user on run time for list of permission generated form manifest file on install time. It's check the permission only once on run time.

You can use the code below ... what I done for you

First declare a variable like this

static final int  REQUEST_CAMERA_PERMISSION = 1;

Then write the method and an override method like this...

private boolean checkPermission(){    
   if (android.os.Build.VERSION.SDK_INT >= 23 &&
   ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)== 
   PackageManager.PERMISSION_DENIED) {
   requestPermissions(new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA_PERMISSION);
      return false;
   }else{
      return true;
   }
}

 @Override
 public void onRequestPermissionsResult(int requestCode, String[]   permissions, int[] grantResults) {
switch (requestCode) {
    case REQUEST_LOCATION_CAMERA:
         if (grantResults[0] == PackageManager.CAMERA) {
                Log.d(TAG,"Premission granted");
         }else {
                Log.d(TAG,"Premission denied");
         }
         break;
}
}

Then where you want to open camera just call the checkPersmission() method like this

if(checkPermission()){
   //your open camera code write hare
}

Fell free to ask if you have any question ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM