Share Image via android app using ACTION_SEND not working

拈花ヽ惹草 提交于 2019-12-05 23:06:53
Harneet Kaur

Simply use following code snippet :

try {
    File myFile = new File("/mnt/sdcard/images/2.png");
    MimeTypeMap mime = MimeTypeMap.getSingleton();
    String ext=myFile.getName().substring(myFile.getName().lastIndexOf(".")+1);
    String type = mime.getMimeTypeFromExtension(ext);
    Intent sharingIntent = new Intent("android.intent.action.SEND");
    sharingIntent.setType(type);
    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();  
} 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!