-2

I found this program online and want to replace the part where it creates a new file to an external storage with creating a new file to internal storage. Please, if you know the answer, can you tell me the exact code to write. I've read other questions on this website and it ends up messing up the program. Thank you.

Layout

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >


<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/desc" />

</LinearLayout>

And the java file

   public class Main extends Activity implements OnClickListener {

private static final int TAKE_PICTURE = 0;
private Uri mUri;
private Bitmap mPhoto;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ((Button) findViewById(R.id.snap)).setOnClickListener(this);
    ((Button) findViewById(R.id.rotate)).setOnClickListener(this);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case TAKE_PICTURE:
        if (resultCode == Activity.RESULT_OK) {
            getContentResolver().notifyChange(mUri, null);
            ContentResolver cr = getContentResolver();
            try {
                mPhoto = android.provider.MediaStore.Images.Media.getBitmap(cr, mUri);
                ((ImageView)findViewById(R.id.photo_holder)).setImageBitmap(mPhoto);
            } catch (Exception e) {
                Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }
    }
}

   @Override
  public void onClick(View v) {
    if (v.getId()== R.id.snap) {
        Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
        File f = new File(Environment.getExternalStorageDirectory(),  "photo.jpg");
        i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
        mUri = Uri.fromFile(f);
        startActivityForResult(i, TAKE_PICTURE);
    } else {
        if (mPhoto!=null) {
            Matrix matrix = new Matrix();
            matrix.postRotate(90);
            mPhoto = Bitmap.createBitmap(mPhoto , 0, 0, mPhoto.getWidth(), mPhoto.getHeight(), matrix, true);
            ((ImageView)findViewById(R.id.photo_holder)).setImageBitmap(mPhoto);
        }
    }
}

}

AbhishekSaha
  • 705
  • 3
  • 9
  • 24

1 Answers1

1

You can't, not taking the picture like this. You're using an intent and taking the picture from another app. That app can't access your internal memory (internal memory is per application). You either need to save to a common directory on external storage, or you need to take the picture yourself.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127