【问题标题】:nativescript angular2 camera errornativescript angular2相机错误
【发布时间】:2016-10-11 14:36:27
【问题描述】:

我正在尝试让相机(硬件访问)在 Windows 10 上的 nativescript angular2 应用程序中工作。

但是在命令提示符中构建后我不断收到错误: - tns 运行安卓

这是我的代码:

app.component.ts

import { Component } from "@angular/core";
import cameraModule = require("camera");
import imageModule = require("ui/image"); 

@Component({
selector: "my-app",
templateUrl: "app.component.html" 
}) 

export class AppComponent {

public takePic() {
    cameraModule.takePicture().then(picture => {
        console.log("Result is an image source instance");
        var image = new imageModule.Image();
        image.imageSource = picture;
    });
}
}

app.component.html

<StackLayout>
<Label text="Take a picture" class="title"></Label>

<Button text="take" (tap)="takePic()"></Button>
<Label [text]="take" class="message" textWrap="true"></Label>

这是我得到的错误:

EXCEPTION: Uncaught (in promise): Error: android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/org.nativescript.camera/files/cameraPicture_1010201614233.jpg exposed beyond app through ClipData.Item.getUri()

【问题讨论】:

    标签: angular camera nativescript


    【解决方案1】:

    我只是在这里猜测,但很可能您正在尝试在 Android N (Android 7) 中拍照,问题是不再允许定位 file:// URI。新概念使用内容提供程序处理文件,并且表示 NativeScript 正在实施新的优化相机模块,该模块还可以处理 Android 的新文件要求。 新的相机模块计划与 NativeScript 2.4.0 一起发布,可以在this repository 找到。

    this thread,您可以找到新相机插件的基本用法,该插件也适用于 imageAssets(同样,如果您想现在测试它,您将需要 tns-core-modules@next,因为这将在版本中发布2.4.0)

    【讨论】:

    • 这帮助我朝着正确的方向前进,谢谢!这是一个很好的猜测,呵呵,我使用的是 android 7 设备
    猜你喜欢
    • 1970-01-01
    • 2022-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多