-1

How to Save Image in Internal Storage and show image in imageView in another acitivity ,please tell me how to save that image in internal storage because many phones have only internal storage not sd card

this is my first acitivity

 //camera
    camera = (ImageView) findViewById(R.id.takePic);
    camera.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File pictureDirectory=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
            String pictureName=getPictureName();
            File imageFile=new File(pictureDirectory,pictureName);
             pictureUri=Uri.fromFile(imageFile);
            intent.putExtra(MediaStore.EXTRA_OUTPUT,pictureUri);
            startActivityForResult(intent,CAMERA_REQUEST_CODE);

        }
    });

 private String getPictureName() {

    SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd_HHmmss");
    String timestamp=sdf.format(new Date());
    return "Plane place image"+timestamp+".jpg";

}

  @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode==RESULT_OK){
        if (resultCode==CAMERA_REQUEST_CODE)
        {
            pictureUri = data.getData();
            if (pictureUri!=null) {
                Intent intent = new Intent(this, PictureActivity.class);
                intent.setData(pictureUri);
                intent.putExtra("imgUrl", pictureUri.toString());
                startActivity(intent);
            }
        }
    }
}

this is my second activity

 Bundle bundle = getIntent().getExtras();

    if (bundle != null) {
        Log.e("ashish", bundle.getString("imgUrl") + "");
         path = Uri.parse(bundle.getString("imgUrl"));

    }

    ImageView selfiiii = (ImageView) findViewById(R.id.mySelfie);
    selfiiii.setImageURI(path);
mohd irfan
  • 57
  • 9

2 Answers2

0

i am store image in emulator internal storage used below code...

private String saveToInternalStorage(Bitmap bitmapImage){
    ContextWrapper cw = new ContextWrapper(getApplicationContext());
     // path to /data/data/yourapp/app_data/imageDir
    File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
    // Create imageDir
    File mypath=new File(directory,"profile.jpg");

    FileOutputStream fos = null;
    try {           
        fos = new FileOutputStream(mypath);
   // Use the compress method on the BitMap object to write image to the OutputStream
        bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, fos);
    } catch (Exception e) {
          e.printStackTrace();
    } finally {
        try {
          fos.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
    } 
    return directory.getAbsolutePath();
}
0

make changes in opencamera method like used below code...

    private void OpenCamera(){
    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(cameraIntent, CAMERA_REQUEST_CODE);
}
 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Bitmap thumbnail = null;

    if (resultCode==RESULT_OK){
        if (requestCode==CAMERA_REQUEST_CODE)
        {
                thumbnail = (Bitmap) data.getExtras().get("data");
                Intent intent = new Intent(this, DbInsert.class);
                intent.putExtra("name", thumbnail);
                startActivity(intent);
            }

    }
}

second Activity...

        Bitmap bitmap  = getIntent().getExtras().getParcelable("name");
    imageView.setImageBitmap(bitmap);