【问题标题】:Android: Share Image on HangoutAndroid:在环聊上分享图片
【发布时间】:2014-08-19 23:01:58
【问题描述】:

我尝试将图像分享到环聊,但“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."));

【问题讨论】:

    标签: android image share hangout


    【解决方案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."));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-18
      • 1970-01-01
      • 1970-01-01
      • 2016-12-23
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2021-12-25
      相关资源
      最近更新 更多