Android:在环聊中分享图片

时间:2014-08-19 23:01:58

标签: android image share hangout

我尝试将图片分享给视频群聊,但“file.exists()”是假的...有什么建议吗?

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."));

1 个答案:

答案 0 :(得分:1)

我发现解决方案,如果有兴趣,但不能与KitKAt(4.4.4)共享图像......

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."));