0

I am currently using a photo gallery I built through GridLayout but this seems to use a lot of memory (OOME coming up) when dealing with a lot of Bitmaps. Therefore, I am trying to use the Intent.ACTION_GET_CONTENT to open photos on the device and select photos through there. The camera function works correctly as it takes the photo, returns to the onActivityResult function, and updates it to my Gridlayout photo gallery.

I am currently on a Nexus 7 running Android 4.4 (KitKat)

[PROBLEMS]

  • When I try to view photos through Intent.ACTION_GET_CONTENT, none of the new photos I just took through the application are there.
  • Running Intent.ACTION_GET_CONTENT to filter results from a specific directory and file type doesn't seem to work.

[Code information]

MainForm is a (class)
photoPath = new File(directory, photoName)
directory is a (File) set to my current working directory
photoName is a (String)
CAMERA_CODE is an (int)

[MY CODE]

Here is my code for launching the camera:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cUri = Uri.fromFile(photoPath);
intent.putExtra(MediaStore.EXTRA_OUTPUT, cUri);
startActivityForResult(intent, CAMERA_CODE); // launch camera

[What I tried + Errors for Updating Photo Gallery library]

MediaScannerConnection

I tried to use this to update the photolist and then launch the intent, but it did not work (I may be using this incorrectly, but it was suggested in this post)

MediaScannerConnection.scanFile(MainForm.this, new String[] { directory.getAbsolutePath() },null, new MediaScannerConnection.OnScanCompletedListener() {
    public void onScanCompleted(String path, Uri uri){
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
        intent.setData(uri);
        intent.setType("image/*");
        startActivityForResult(Intent.createChooser(intent,"Select Picture"), 12345);
    }
});

getContentResolver()

I read in this question to try using this method, but it doesn't seem to work either

MainForm.this.getContentResolver().notifyChange(MediaStore.Images.Media.INTERNAL_CONTENT_URI, null);

sendBroadcast

In this question and here to re-index photos on the device, the answer suggested using sendBroadcast

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.fromFile(directory)));

but I was greeted with this error

E/AndroidRuntime(30177): java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=30177, uid=10122

What does this error mean?

[What I tried + Errors for ACTION_GET_CONTENT intent]

No matter what I put under intent.setData, opening the intent doesn't seem to open that folder, but instead it opens the android browser under the tab "Recent"

I followed this question

ANY TIPS OR SUGGESTIONS WOULD BE GREATLY APPRECIATED! If there are any other codes or log results I should post, please comment below!

Community
  • 1
  • 1
Jason Kim
  • 1
  • 1
  • have you added `android.intent.action.MEDIA_MOUNTED` permission in `AndroidManifest.xml` ? – ρяσѕρєя K Mar 04 '14 at 05:28
  • I have that permission added, but still the same error. From [this post](http://stackoverflow.com/questions/21469431/permission-denial-not-allowed-to-send-broadcast-in-android), apparently broadcast doesn't work anymore on Android 4.4? I am currently on a Nexus 7 running 4.4 (KitKat) – Jason Kim Mar 04 '14 at 05:42

0 Answers0