繁体   English   中英

如何显示在Android Gallery中从应用程序拍摄的图像?

[英]How to display images taken from app in android gallery?

我想在手机图库中显示我的应用程序中相机拍摄的图像。 图像已保存到文件夹,但不显示在图库中?

这是我的代码,但这似乎不起作用。

 getApplicationContext().getDir(
              getResources().getString(R.string.app_name), MODE_PRIVATE);

          fileUri = Uri.fromFile(new File((Environment.getExternalStorageDirectory() +
                  "/" +getResources().getString(R.string.app_name)),new Date().getTime() + ".jpg"));
          Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
          takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
          startActivityForResult(takePictureIntent,TAKE_PICTURE);
  }

       public void onActivityResult(int requestCode, int resultCode, Intent data) {
          if (requestCode == TAKE_PICTURE && resultCode == RESULT_OK) {

                  try {
                      GetImageThumbnail getImageThumbnail = new GetImageThumbnail();
                      bitmap = getImageThumbnail.getThumbnail(fileUri, this);
                  } catch (FileNotFoundException e1) {
                      e1.printStackTrace();
                  } catch (IOException e1) {
                      e1.printStackTrace();
                  }

       protected void mediaScan() {
            getApplicationContext().sendBroadcast(
                    new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, 
                            Uri.parse(fileUri.toString())));
        }

有什么建议么? 谢谢

您应该将图片保存在Picture公共目录中,并在onActivityResult中调用mediaScan()

暂无
暂无

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

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