Android 添加 在清单中

发布于 2024-11-04 21:18:47 字数 128 浏览 5 评论 0 原文

我很困惑在哪里添加

使用功能

使用清单中的 标签。 我正在我的应用程序中使用相机。我添加了权限,但我很困惑在哪里添加功能才能使用前置摄像头。你能帮忙吗?

I am pretty confused where to add the

uses-feature

tag in the manifest.
I am using the camera in my app. I added permission but I'm confused where to add features in order to use front facing camera. Can you help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

春夜浅 2024-11-11 21:18:47

< sustest> 标签下添加它:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              package="com.lalllala">
       <uses-permission android:name="android.permission.INTERNET" />
       <uses-permission android:name="android.permission.VIBRATE" />
       <uses-feature android:name="android.hardware.camera" />
          <application android:icon="@drawable/icon" android:label="lalla" android:debuggable="true">

          </application>
    </manifest>

Add this under <manifest> tag, like this:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              package="com.lalllala">
       <uses-permission android:name="android.permission.INTERNET" />
       <uses-permission android:name="android.permission.VIBRATE" />
       <uses-feature android:name="android.hardware.camera" />
          <application android:icon="@drawable/icon" android:label="lalla" android:debuggable="true">

          </application>
    </manifest>
绻影浮沉 2024-11-11 21:18:47

- 声明应用程序使用的单个硬件或软件功能。

声明的目的是告知任何外部实体您的应用程序所依赖的硬件和软件功能集。该元素提供了一个 required 属性,可让您指定应用程序是否需要且在没有声明的功能的情况下无法运行,或者是否希望拥有该功能但在没有该功能的情况下也可以运行。由于功能支持可能因 Android 设备而异,因此该元素在让应用程序描述其使用的设备变量功能方面发挥着重要作用。
阅读更多内容

如下是访问设备前置摄像头的示例代码

public Camera openFrontFacingCamera() {
int cameraCount = 0;
Camera ffCam = null;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();

// Find the total number of cameras available
cameraCount = Camera.getNumberOfCameras();

// Find the ID of the CAMERA_FACING_FRONT & open it
for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
    Camera.getCameraInfo(camIdx, cameraInfo);
    if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        try {
            ffCam = Camera.open(camIdx);
        } catch (RuntimeException e) {
            Log.e(TAG, "Camera failed to open: " + e.getLocalizedMessage());
        }
    }
}

    return ffCam;
}

需要以下权限

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

有关更多信息,请阅读Google android开发者API文档 相机Camera.CameraInfo

<uses-feature> - Declares a single hardware or software feature that is used by the application.

The purpose of a declaration is to inform any external entity of the set of hardware and software features on which your application depends. The element offers a required attribute that lets you specify whether your application requires and cannot function without the declared feature, or whether it prefers to have the feature but can function without it. Because feature support can vary across Android devices, the element serves an important role in letting an application describe the device-variable features that it uses.
read for more

Below is sample code to access Device Front Camera

public Camera openFrontFacingCamera() {
int cameraCount = 0;
Camera ffCam = null;
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();

// Find the total number of cameras available
cameraCount = Camera.getNumberOfCameras();

// Find the ID of the CAMERA_FACING_FRONT & open it
for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
    Camera.getCameraInfo(camIdx, cameraInfo);
    if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        try {
            ffCam = Camera.open(camIdx);
        } catch (RuntimeException e) {
            Log.e(TAG, "Camera failed to open: " + e.getLocalizedMessage());
        }
    }
}

    return ffCam;
}

Need following permissions

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

For more please read Google android developer API doc Camera, Camera.CameraInfo

千柳 2024-11-11 21:18:47

在清单标签下添加此内容:

<!-- Request the camera permission -->
    <uses-permission
        android:name="android.permission.CAMERA" />
    <uses-feature
        android:name="android.hardware.camera"
        android:required="true" />

Add this under manifest tag:

<!-- Request the camera permission -->
    <uses-permission
        android:name="android.permission.CAMERA" />
    <uses-feature
        android:name="android.hardware.camera"
        android:required="true" />
雾里花 2024-11-11 21:18:47

像这样编写标签顺序

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

    <uses-feature android:name="android.hardware.camera.autofocus" />

    <application>

    </application>
</manifest>

write tags order like this

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

    <uses-feature android:name="android.hardware.camera.autofocus" />

    <application>

    </application>
</manifest>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文