【问题标题】:How to display images taken from app in android gallery?如何在android图库中显示从应用程序拍摄的图像?
【发布时间】:2014-12-07 10:04:15
【问题描述】:

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

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

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

有什么建议吗? 谢谢

【问题讨论】:

    标签: android android-gallery


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-31
      • 1970-01-01
      • 1970-01-01
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多