图片显示不出来图库 [英] Photo does not show up to gallery

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

问题描述

我试图把使用Android相机中的照片,并告诉它保存到手机的画廊。我想我搞砸的道路上,但我似乎无法找到我的错误。有人能帮助我吗?我非常新手在机器人。

code调用相机

 意图cameraIntent =新的意图(android.provider.MediaStore.ACTION_IM​​AGE_CAPTURE);
                  字符串uriToFileInExternalStorage = NULL;
                    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,uriToFileInExternalStorage);
                    startActivityForResult(cameraIntent,CAMERA_PIC_REQUEST);
 

code处理的照片,并告诉它去画廊。

 保护无效onActivityResult(INT申请code,INT结果code,意图数据){
            如果(要求code == CAMERA_PIC_REQUEST){
                //检查相机拍摄的照片通过检查请求code

                Toast.makeText(MainActivity.this,照片捕捉,Toast.LENGTH_SHORT).show();


                开放的我们的mpath = data.getData();
                 意图mediaScanIntent =新的意图(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);

                    mediaScanIntent.setData(的mpath);
                    this.sendBroadcast(mediaScanIntent);

            }
        }
 

解决方案

在这里尝试给出code:的添加照片至图库

 意图mediaScanIntent =新的意图(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
文件F =新的文件(mCurrentPhotoPath);
乌里contentUri = Uri.fromFile(F);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
 

我建议您下载的例子 PhotoIntentActivity 阅读和理解如何取 mCurrentPhotoPath 值。

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.

Code to call camera

   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);

            }
        }

解决方案

Try code given here: Add the Photo to a Gallery

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);

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

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

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