The image is saved in the desired folder but it is not being displayed in imageView nor the Toast is being displayed.I have tried with with almost every method like using different XML files and changing class as well but the problem still resides.
package com.example.mohammadhasham.jtbopencameramodule;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.icu.text.SimpleDateFormat;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import java.io.File;
import java.util.Date;
public class CameraActivity extends AppCompatActivity {
ImageView img;
String currentPath;
File f;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
img = (ImageView) (findViewById(R.id.capture));
}
public void captureImage(View v) {
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "image.jpg");
Uri u = Uri.fromFile(f);
i.putExtra(MediaStore.EXTRA_OUTPUT, u);
i.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(i, 0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == 0) {
switch (resultCode) {
case Activity.RESULT_OK:
{
if (f.exists())
{
Toast.makeText(this, "Image Saved To Gallery", Toast.LENGTH_LONG).show();
Bitmap b = BitmapFactory.decodeFile(f.getAbsolutePath());
img.setImageBitmap(b);
}
else
{
Toast.makeText(this, "Image Not Saved To Gallery", Toast.LENGTH_LONG).show();
}
break;
}
case Activity.RESULT_CANCELED:
{
break;
}
default:
break;
}
}
}
}
The image is saved in the desired folder. Strange start of your post. Which image? Tell what happens from the start. After that show your code.