不支持意图图像共享文件格式

时间:2017-08-17 20:19:47

标签: android android-intent android-intent-chooser

我无法与社交媒体分享图片 当我点击分享按钮。 它显示了Toast

  

不支持文件格式

public void onBindViewHolder(final ViewHolder holder, int position) {
         upload = uploads.get(position);

       holder.textViewName.setText(upload.getName());
       final String imageUrl=upload.getUrl();


        Glide.with(context).load(imageUrl).into(holder.imageView);

        final Uri imageUri=Uri.parse("https://firebasestorage.googleapis.com/v0/b/memories-project.appspot.com/o/uploads%2FnCfBZThQykf3Ur9oNzHyEHS1DEp2%2F45007?alt=media&token=9ae17594-13ff-40f6-98f9-aff80ab2fdf4");
        holder.shareImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context,imageUrl,Toast.LENGTH_SHORT).show();
                Intent shareIntent = new Intent();
                shareIntent.setAction(Intent.ACTION_SEND);
                shareIntent.setType("image/*");

                shareIntent.putExtra(Intent.EXTRA_STREAM,imageUri);

                shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                try {
                    context.startActivity(Intent.createChooser(shareIntent, "Share image File"));
                } catch (android.content.ActivityNotFoundException ex) {

                }
            }
        });
    }

我将图片存储到firebase。 现在我从firebase获得链接并解析为uri,但我不知道为什么会这样。

  

我为了测试目的而对URL进行了硬编码。

对于WhatsApp:

  

不支持文件格式

对于Instagram:

  

图片无法加载

对于Facebook:

  

没有显示没有Toast或任何东西(只显示状态栏)

对于Messenger:

  

未打开

1 个答案:

答案 0 :(得分:1)

引用the documentationEXTRA_STREAM应该指向“content: URI,其中包含与Intent相关联的数据流,与ACTION_SEND一起使用提供正在发送的数据。“

您正在提供https Uri,其他应用也不会期待它。并非所有支持ACTION_SEND的应用都拥有INTERNET权限。

如果您想要分享某些内容,通常需要在设备上提供本地内容,并通过FileProvider或其他形式的ContentProvider进行分享。在Android 7.0之前,指向external storage上的文件的file方案通常也可以。

相关问题