Im trying to share an image, it seems to work only when the SD card is mounted or when the phone doesn't have a SD card slot. But when I dismount the SD card, it wouldn't share and it gives me two errors.
FATAL EXCEPTION: main java.lang.NullPointerException: uriString
Failed to insert image java.io.FileNotFoundException: No such file or directory
And for some reason it also saves the image that is being shared, can't seem to figured out why.
private Button button;
public void onCreate {
init();
setupView();
}
public void setupView(){
button.setOnClickListener(this);
}
public void init() {
button = (Button) findViewById(R.id.button);
}
@Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.button: {
startShare();
break;
}
public void startShare() {
Bitmap b =BitmapFactory.decodeResource(getResources(),R.drawable.m1);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = MediaStore.Images.Media.insertImage(getContentResolver(),
b, "Title", null);
Uri imageUri = Uri.parse(path);
share.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(share, "Share"));
}