nativescript-camera
nativescript-camera copied to clipboard
API17 (Android SDK 4.2) Camera can't take photos, app crashes
ActivityManager: START u0 {act=android.media.action.IMAGE_CAPTURE cmp=com.asus.camera/.CameraApp (has extras)} from pid 11106 ActivityManager: Process org.kct.fiberstar (pid 11106) has died.
https://www.youtube.com/watch?v=FKemwn75AYE&feature=youtu.be
the app die when i open the camera,
asus t001 (zenfone) ram 1 GB android 4.4.2 nativescript 3.4.2 nativescript-camera 3.2.1
tns info │ Component │ Current version │ Latest version │ Information │ │ nativescript │ 3.4.2 │ 3.4.2 │ Up to date │ │ tns-core-modules │ 3.4.0 │ 3.4.0 │ Up to date │ │ tns-android │ 3.4.1 │ 3.4.1 │ Up to date │ │ tns-ios │ 3.4.1 │ 3.4.1 │ Up to date │
@wiliarko please provide a sample application demonstrating the issue - I have used the demo applications and the camera is taking photos as expected.
In your youtube video, there is a log related to missing recourse files Missing image with resources
- where is this image used? Consider providing demo app so we could investigate further.
I'm sorry, this is a simpler video, where when the button is pressed then the camera will open and in the log will be written dead application. after the photo taken the app will look like a restart application before it was dead
https://youtu.be/EvyQeztaI2E
in the background video is the code
i already try this aplication using my mobile phone and it not works, but if i try using another mobile phone with higher spesification it runs well
@wiliarko it is hard to debug a code from a YouTube video :)
However, I've noticed that this line
this.set("cameraImageasset", imageAsset)
This line is placed inside the camera promise and as you are using plain JavaScript function as callback the meaning of this
is not the same as the meaning of this
outside the scope of that function.
So you can use that-this pattern and store the meaning of this. For example:
viewModel.onTap = function() {
var that = this;
// more code follows here ....
camera.takePicture().then(function(imageAsset) {
that.set("cameraImageasset", imageAsset); // note we are using **that**
})
}
Note: If your project is using TypeScript then you can use TS arrow function where the meaning of this is the same as the meaning of
this
in the global context.
it's code model
var Observable = require("data/observable").Observable;
var camera = require("nativescript-camera");
function getMessage(counter) {
if (counter <= 0) {
return "Hoorraaay! You unlocked the NativeScript clicker achievement!";
} else {
return counter + " taps left";
}
}
function createViewModel() {
var viewModel = new Observable();
viewModel.counter = 42;
viewModel.message = getMessage(viewModel.counter);
viewModel.set("cameraImagePath","http://sedekahlistrik.com/foto/deff.jpg");
viewModel.onTap = function() {
camera.requestPermissions();
var options = { width: 100, height: 100, keepAspectRatio: false, saveToGallery: true };
camera.takePicture().
then(function (imageAsset) {
viewModel.set("cameraImagePath", imageAsset);
}, function (err) {
console.log("Error -> " + err.message);
});
}
return viewModel;
}
exports.createViewModel = createViewModel;
it's view
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="onNavigatingTo" class="page">
<Page.actionBar>
<ActionBar title="My App" icon="" class="action-bar">
</ActionBar>
</Page.actionBar>
<StackLayout class="p-20">
<Label text="Tap the button" class="h1 text-center"/>
<Button text="TAP" tap="{{ onTap }}" class="btn btn-primary btn-active"/>
<Label text="{{ message }}" class="h2 text-center" textWrap="true"/>
<Image src="{{ cameraImagePath }}" width="100%" height="200" margin="10" loadMode="async" decodeWidth="400" decodeHeight="400"/>
</StackLayout>
</Page>
and it's controler
var createViewModel = require("./main-view-model").createViewModel;
function onNavigatingTo(args) {
var page = args.object;
page.bindingContext = createViewModel();
}
exports.onNavigatingTo = onNavigatingTo;
it's the new video
https://youtu.be/eAZkWgqu8o8
left side is smartphone lower spesification android 4.4 asus zenfone and ram 1 GB it not works,
right is emulator android 6.0 and ram 2GB it runs well
@wiliarko I was able to reproduce the issue on device with API 17 - will investigate further and post any additional info here.
Steps to reproduce: use the demo app on API17 device/emulator
Happens also in Galaxy S5, android version 6 (6.0.1), and i pass the options:
{ width: 1000, height: 1000, keepAspectRatio: true, saveToGallery: false, cameraFacing: "front" }
@wiliarko did you try to pass the options
json to your takePicture()
?
Galaxy S5, android version 6 (6.0.1) +1. I tried to run the demo(which the default width and height is 300) on S5, which takes about 3 times to crash the phone. If I change the size to 900 then Its nearly crashed every time for just 1 photo.
I've found that when the app goes to the camera it picks it up as leaving the app, and after taking the photo it goes through the app.js file when resuming the app. Just check if it hits the app.js file, then you just need to stop it from doing anything and it will go back to your last page automatically.
I'm using angular here, doesn't have a choice to change the app.js . But I have tried on 4 android phones now, only the S5 6.0.1 have this issue. The other 3 are Android 8.0 and Android 7.0. Not sure if it's related to the OS version.
Anyone working on this? I'm experiencing the same thing on a Google Pixel 3.
Same problem on Xiaomi phones