简体   繁体   English

在Android上拍照关闭应用程序

[英]Taking Picture on Android Closes App

I am making an Android app that can take a picture and save it to the gallery. 我正在制作一个可以拍照并将其保存到图库的Android应用。 However, after taking the picture and tapping on the checkmark, the camera intent dismisses but the app is closed and the picture is not saved. 但是,在拍摄图片并点击对勾后,相机意图消失了,但应用程序已关闭并且图片未保存。

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File pictureDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    String imageName = "Blah.jpg";
    File imageFile = new File(pictureDirectory, imageName);
    Uri pictureUri = Uri.fromFile(imageFile);
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);
    startActivityForResult(cameraIntent,1313);

The intent successfully launches but the following is never called and the app just closes: 该意图成功启动,但以下任何一项从未调用,并且该应用程序仅关闭:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1313 && resultCode == RESULT_OK) {
        //...
    }
}

您需要使用FileProvider来获取文件URI,并为上述牛轧糖添加授予用于读取URI的意图标志。 )请按照以下步骤操作:android.os.FileUriExposedException:file:///storage/emulated/0/test.txt通过Intent.getData()在应用程序之外公开

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM