[英]Expo-image-picker crashes app after using launchCameraAsync() on Android
I'm using expo-image-picker to allow the user to pick and take pictures.我正在使用 expo-image-picker 来允许用户选择和拍照。 Choosing an image from the library works as expected but when using the camera, after taking the picture the app crashes.
从库中选择图像按预期工作,但在使用相机时,拍照后应用程序崩溃。 Here is my code:
这是我的代码:
const take = async () => {
let result = await ImagePicker.launchCameraAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
quality: 1,
});
console.log(result.uri);
if (!result.cancelled) {
setImageUri(result.uri);
}
};
I think I have all the required permissions and the problem seems to occur only on older android devices with limited memory.我想我拥有所有必需的权限,而且问题似乎只发生在内存有限的旧版 Android 设备上。 Any ideas?
有任何想法吗?
There is no good and easy solution.没有好的和简单的解决方案。
What is happening is, when you launch the camera, it launches as a new Activity
, leaving your app mainActivity
in background.发生的事情是,当您启动相机时,它会作为一个新的
Activity
启动,将您的应用程序mainActivity
在后台。
From Android P (9) and on, the OS can kill your background activity.从 Android P (9) 开始,操作系统可以终止您的后台活动。 There is even a website just about whose implementation is worse for devs: https://dontkillmyapp.com/
甚至有一个网站的实施对开发人员来说更糟糕: https ://dontkillmyapp.com/
Possible solutions:可能的解决方案:
ImagePicker.getPendingResultAsync
.ImagePicker.getPendingResultAsync
获取照片。mainActivity
but needs boring reimplementation, and don' t look as good as the manufacturer native cameras.mainActivity
上使用相机但需要无聊的重新实现,并且看起来不如制造商原生相机。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.