简体   繁体   English

相机许可在Sumsung galaxy s6 android V.6上未激活

[英]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! 我的应用无法打开银河S6上的前置摄像头,我不知道为什么请帮忙! 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. 因此,当我在S6 android v6上运行应用程序时,它根本无法打开前置摄像头,但在另一个android 4-5版本上就可以了。 what should i do ? 我该怎么办 ?

For android v.6 permission form mamifest not enough .... 对于android v.6权限表mamifest不够....

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. 在所有版本的Android上,您的应用都需要在其应用清单中声明其正常权限和危险权限,如声明权限中所述。 However, the effect of that declaration is different depending on the system version and your app's target SDK level: 但是,根据系统版本和应用程序的目标SDK级别,该声明的效果是不同的:

  • 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; 如果设备运行的是Android 5.1或更低版本,或者您的应用的目标SDK是22或更低版本:如果您在清单中列出了危险权限,则用户在安装应用时必须授予该权限; 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. 如果设备运行的是Android 6.0或更高版本,并且您的应用程序的目标SDK是23或更高版本:该应用程序必须在清单中列出权限,并且在运行该应用程序时,它必须请求所需的每个危险权限。 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 然后在要打开相机的地方只需调用checkPersmission()方法,如下所示

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

Fell free to ask if you have any question ... 随意询问您是否有任何问题...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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