0

Good afternoon, I have the following code in Android for take a photo and show in ImageView, the file photo is in the path when I check with filemanager, but dont show in ImageView and have the following message:

E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/S3TAUDIT/photos/S3actual.png (No such file or directory)

Please I need your help for finish my app. I use API 25 Android 7, permissions, options.inJustDecodeBounds. I have reviewed all posts with this error type and dont find solutions.

Thanks a lot.

package com.example.jorge.s3taudit;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Environment;
import android.os.StrictMode;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;

import java.io.File;

public class PICSSECTOR extends AppCompatActivity {

    private final String carpeta_raiz="S3TAUDIT/";
    private final String ruta_imagen=carpeta_raiz+"photos";
    String path;

    ImageView pics1actual;

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_picssector);

public void pics1actual(View view) {
        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
        File pics1actualpng= new File(Environment.getExternalStorageDirectory(),ruta_imagen);
        boolean isCreada =pics1actualpng.exists();
        String nombre_imagen ="";
        if (isCreada == false){
            isCreada = pics1actualpng.mkdirs();
            nombre_imagen = "S3actual.png";
        }
        if (isCreada==true){
            nombre_imagen = "S3actual.png";
        }
        path = Environment.getExternalStorageDirectory()+File.separator +ruta_imagen+File.separator+ nombre_imagen;

        File pics1actual =new File(path);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(pics1actual));
        startActivityForResult(intent, 0);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
            if (requestCode == 0) {
                MediaScannerConnection.scanFile(this, new String[]{path}, null,
                        new MediaScannerConnection.OnScanCompletedListener() {
                            @Override
                            public void onScanCompleted(String s, Uri uri) {
                                Log.i("RUTA de almacenamiento", "Path: " + path);
                            }
                        });
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = false;
                ImageView pics1actual = (ImageView) findViewById(R.id.s1actual);
                Bitmap bitmap = BitmapFactory.decodeFile(path,options);
                pics1actual.setImageBitmap(bitmap);
          }

    }
}

The xml only for this action is:

 <ImageView
                android:id="@+id/s1actual"
                android:layout_width="0dp"
                android:layout_height="150dp"
                android:layout_margin="4dp"
                android:layout_weight="1"
                android:background="#DDDDDD" />

 <Button
                android:id="@+id/ButtonPICS1actual"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:drawableStart="@drawable/ic_stat_name"
                android:onClick="pics1actual"
                android:text="PHOTO"
                android:textSize="20dp" />

This image I have in Debugger

enter image description here

Bruno
  • 3,872
  • 4
  • 20
  • 37
  • I think there's been other problem like this in Android. It's a bug where ACTION_MEDIA_CAPTURE does not work properly. See here https://stackoverflow.com/questions/1910608/android-action-image-capture-intent – gumil Oct 04 '19 at 09:17
  • Hi Miguel, thanks for your comments, but the photo file was created in path, the problem is that the bitmap is null. – Jorge Zambrano Oct 04 '19 at 12:15
  • With the stackoverflow thread I linked, the image might not be saved in that file. Making the file path you are referencing non existent. you can try debugging if at the point you are decoding the bitmap if the file exists – gumil Oct 04 '19 at 12:50
  • Hi Miguel, the file exists, this I can review in path and open without problem – Jorge Zambrano Oct 06 '19 at 11:45

0 Answers0