Intent image share-file format not supported

偶尔善良 提交于 2019-12-11 00:39:54

问题


I'm unable to share image to social media when i clicked on share button. It showed the Toast

File format not supported

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) {

                }
            }
        });
    }

I stored images to firebase. Now i get the link from firebase and parse into uri but i don't know why this is showing.

I hardcoded the URL just for testing purpose.

For WhatsApp:

File Format not supported

For Instagram:

Image Unable to load

For Facebook :

Showed nothing means no Toast or anything(Just Showed the status bar)

For Messenger:

Not opened


回答1:


Quoting the documentation, EXTRA_STREAM is supposed to point to "A content: URI holding a stream of data associated with the Intent, used with ACTION_SEND to supply the data being sent."

You are supplying an https Uri, and other apps will not be expecting it. Not every possible app that supports ACTION_SEND will have the INTERNET permission, anyway.

If you want to share some content, typically it needs to be local on the device and shared via a FileProvider or some other form of ContentProvider. Prior to Android 7.0, a file scheme pointing to a file on external storage often works as well.



来源:https://stackoverflow.com/questions/45744296/intent-image-share-file-format-not-supported

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!