0

Basically what I'm trying to do is allow the user to take a picture, then after they save the picture they can open the gallery(inside the app) and view the picture. However the pictures do not show show up in the gallery. This is what I have thus far. This is what the directory looks like when a picture is taken and saved:

/storage/sdcard0/Android/data/'my app'/files/ArcFlash/study1/Transformer/trans1/trans1_time_date.png

After the picture intent, I have my onActivityResult(I compress the picture):

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == 1)
    {
        if(resultCode == RESULT_OK)
        {
            SharedPreferences sharedPrefs = getSharedPreferences("userPrefs", Context.MODE_PRIVATE);
            String path = sharedPrefs.getString("path", null);

            filesToScan.add(path);//ex: /storage/sdcard0/Android/data/'my app'/files/.... 

            Bitmap capturedImage;

            if(path != null)
            {
                capturedImage = BitmapFactory.decodeFile(path);

                //Bitmap bitmap = Bitmap.createScaledBitmap(capturedImage, 60, 60, true);
                File newPic = new File(path);

                FileOutputStream fos = null;
                try {
                    fos = new FileOutputStream(newPic);
                    capturedImage.compress(Bitmap.CompressFormat.JPEG, 70, fos);
                    fos.flush();
                    fos.close();

                    String test = "file://"+ context.getExternalFilesDir(null).toString() + "/ArcFlash/";

                    for(int i = 0; i < filesToScan.size(); ++i)
                    {
                        File pic = new File(filesToScan.get(i));
                        Uri uri = Uri.fromFile(pic);
                        sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, uri));
                    }
                }
                catch(Exception ex)
                {
                    handler.Log(ex.getMessage(), "onActivityResult()", context);
                    Log.i("customException", "error compressing image: " + ex.getMessage());
                }
            }
        }
    }
}

my filesToScan is an ArrayList<String>

john
  • 3,949
  • 7
  • 34
  • 56
  • how is that even possible if my code is completely different and I have a different username? Besides the fact that I'm using `context.getExternalFilesDir` and he is using `Environment.getExternalStorageDirectory()` – john Mar 04 '14 at 16:40
  • 2
    Your code is sending `ACTION_MEDIA_MOUNTED`, which is inappropriate and does not work on Android 4.4+. The question I pointed you to provides more appropriate solutions. I fail to see what your username has to do with matters. – CommonsWare Mar 04 '14 at 16:44
  • 1
    @john - it is a duplicate *problem* in that it comes from trying to use the same improper and no-longer-available mechanism as the other poster was. Same problem, same solution = "duplicate question" for purposes of this website. – Chris Stratton Mar 04 '14 at 17:39
  • ok that makes sense. duly noted. The reason why I asked it was because I used it before and it worked perfectly(about 2 weeks ago) until I changed directories from `Environment.getExtern...` to `context.GetExternalFilesDir` – john Mar 04 '14 at 18:08

0 Answers0