Reputation: 849
I'm trying to get the camera (hardware acces) to work in a nativescript angular2 app on Windows 10.
But i'm keep getting errors after building in the command promp: - tns run android
this is my code:
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>
and this is the error i'm getting:
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()
Upvotes: 0
Views: 361
Reputation: 9670
I am just guessing here but most probably you are trying to take a picture in Android N (Android 7) and the thing is that targeting file://
URIs are not allowed anymore. The new concept deals with files using content provider and that said NativeScript is implementing new optimized camera module which also handles the new files requirements for Android.
The new camera module is scheduled to be released with NativeScript 2.4.0 and can be found at this repository.
At this thread, you can find a basic usage of the new camera plugin which also works with imageAssets (again if you want to test it now you will need tns-core-modules@next as this will be released in version 2.4.0)
Upvotes: 1