照片未显示在图库中 [英] Photo does not show up to gallery

查看:24
本文介绍了照片未显示在图库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 android 相机拍照并告诉它保存到手机的图库中.我想我在路上搞砸了,但我似乎找不到我的错误.有人可以帮助我吗?我是android的新手.

I'm trying to take a photo using the android camera and telling it to save to the phone's gallery. I think i messed up on the path, but i can't seem to find my error. Could someone help me? I'm very novice at android.

调用相机的代码

   Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                  String uriToFileInExternalStorage = null;
                    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriToFileInExternalStorage);
                    startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);

处理照片的代码并告诉它去画廊.

code to handle photo and tell it to go to gallery.

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (requestCode == CAMERA_PIC_REQUEST) {
                //check if camera has taken picture by checking request code

                Toast.makeText(MainActivity.this, "Photo Captured", Toast.LENGTH_SHORT).show();


                Uri mPath=data.getData();
                 Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);

                    mediaScanIntent.setData(mPath);
                    this.sendBroadcast(mediaScanIntent);

            }
        }

推荐答案

试试这里给出的代码:将照片添加到图库

Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(mCurrentPhotoPath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);

我建议您下载示例 PhotoIntentActivity 以阅读并了解如何获取 mCurrentPhotoPath 值.

I would suggest you to download example PhotoIntentActivity to read and understand how to fetch mCurrentPhotoPath value.

这篇关于照片未显示在图库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆