简体   繁体   中英

How to display images taken from app in android gallery?

i want to display my images taken by the camera within my app in the gallery of the phone. The images are saved to a folder but doesn't show in Gallery?

here is my code i have but this doesn't seem to work.

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

Any suggestions? Thanks

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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