Share Image Is Not Working Via Action.send
I am sharing image on facebook using ACTION_SEND, but its not working .code is here try { File myFile = new File('/mnt/sdcard/DCIM/100MEDIA/aa.jpg');
Solution 1:
Try this way,hope this will help you to solve your problem.
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
File myFile = newFile(Environment.getExternalStorageDirectory()+"/100MEDIA/aa.jpg");
Intent sharingIntent = newIntent("android.intent.action.SEND");
sharingIntent.setType(getMimeType(myFile.getPath()));
sharingIntent.putExtra("android.intent.extra.STREAM",Uri.fromFile(myFile));
startActivity(Intent.createChooser(sharingIntent,"Share using"));
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),Toast.LENGTH_SHORT).show();
}
}
publicStringgetMimeType(String filePath) {
Stringtype = null;
String extension = getFileExtensionFromUrl(filePath);
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
returntype;
}
publicStringgetFileExtensionFromUrl(String url) {
int dotPos = url.lastIndexOf('.');
if (0 <= dotPos) {
return (url.substring(dotPos + 1)).toLowerCase();
}
return"";
}
Post a Comment for "Share Image Is Not Working Via Action.send"