user4030668
user4030668

Reputation:

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

Upvotes: 0

Views: 84

Answers (1)

Patrick Chan
Patrick Chan

Reputation: 1029

You should save the picture in Picture public directory and call mediaScan() inside the onActivityResult

Upvotes: 1

Related Questions