Share Image From Sd Card
I'm trying for 2 weeks to find how to share images which are stored on an SD card with no success. This answer doesn't work to me, nor is it what I'm looking for. I'm working with
Solution 1:
Well, I finally found a solution to this, but it's not exactly what I want:
g.setOnItemClickListener(newOnItemClickListener() {
publicvoidonItemClick(AdapterView<?> parent, View v, int position, long id) {
Intentintent=newIntent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/Cam App"), "image/*");
startActivityForResult(Intent.createChooser(intent, "Select image to share:"), SELECT_PICTURE);
}
});
}
publicvoidonActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
UriselectedImageUri= data.getData();
//OI FILE Manager
filemanagerstring = selectedImageUri.getPath();
//MEDIA GALLERY
selectedImagePath = getPath(selectedImageUri);
//NOW WE HAVE OUR WANTED STRINGif(selectedImagePath!=null)
System.out.println("selectedImagePath is the right one for you!");
else
System.out.println("filemanagerstring is the right one for you!");
IntentshareIntent=newIntent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, selectedImageUri);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share image via:"));
}
}
}
@SuppressWarnings("deprecation")public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursorcursor= managedQuery(uri, projection, null, null, null);
if(cursor!=null) {
//HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL//THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIAintcolumn_index= cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
elsereturnnull;
}
If somebody has any better solution, please share.
Solution 2:
The following code works fine, If you know the path of that image
Intent shareit=newIntent(Intent.ACTION_SEND);
shareit.setType("image/jpeg");
Filef=newFile("imagepath");
shareit.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
startActivity(Intent.createChooser(shareit, "Share Image Via"));
Create the file with image file name,
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "image_file.jpg");
Post a Comment for "Share Image From Sd Card"