mardi 26 mai 2015

Sharing Image via Intent failed

I am trying to capture image and then share it with apps.

private static final int CAMERA_REQUEST = 1888;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_result);

        Intent cameraIntent = new Intent(
               android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

        startActivityForResult(cameraIntent, CAMERA_REQUEST);
        //start the camera and capture an image
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {

        Uri imageUri = data.getData();
        //convert captured Image from Intent form to URI

        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
        shareIntent.setType("image/jpeg");
        startActivity(shareIntent);
        //share the image

    }
}

But when I run this code, the image doesn't get shared. Is there a bug in my code?

Is there any other way to share an image without saving it in memory?

Aucun commentaire:

Enregistrer un commentaire