Search code examples
androidimagesharegoogle-hangouts

Android: Share Image on Hangout


I try to share an image to hangouts, but "file.exists()" is false... Any suggestions?

Intent hangouts = new Intent(Intent.ACTION_SEND);
if(!Utilities.isNullorEmpty(urlImage)){
   File file = new File(urlImage + JPEG_EXT);
   hangouts.setType(MIME_TYPE_IMG);
   if(Utilities.copyFile(urlImage, file.getPath()) && file.exists()){
      hangouts.putExtra(Intent.EXTRA_STREAM, file.getPath());
   }else{
      Log.e(TAG, "Unable to locate the image on disk, sending mail without attached image.");
   }
}else{
   hangouts.setType(MIME_TYPE_TP);
}
hangouts.setPackage(PACKAGE_H);
hangouts.putExtra(Intent.EXTRA_TEXT, message + ": \n" + urlShare);
startActivity(Intent.createChooser(hangouts, "Hangouts is not installed."));

Solution

  • i found solution, if anyone interested, but dont works with KitKAt (4.4.4) to Share images...

    Intent hangouts = new Intent(Intent.ACTION_SEND);
                if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2){
                    if(!UtilIf anyone is interested.isNullorEmpty(imgPath)){
                        String file = (String)imgPath.subSequence(0, imgPath.lastIndexOf("/") + 1) + message.replace(" ", "").replace(":", "").replace(".", "")
                                .replace("/", "") + ".jpeg";
                        Utilities.copyFile(imgPath, file);
                        hangouts.setType("image/*");
                        hangouts.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///" + file));
                    }
                }
                hangouts.setPackage("com.google.android.talk");
                hangouts.setType("text/plain");
                hangouts.putExtra(Intent.EXTRA_TEXT, message + ": \n" + urlShare);
                ctx.startActivity(Intent.createChooser(hangouts, "Hangouts is not installed."));