如何使用共享文本发送图像

sid*_*rth 1 android android-intent android-sharing

目前我正在使用以下代码来共享文本:

Intent i = new Intent(android.content.Intent.ACTION_SEND);
    i.setType("text/plain");

    i.putExtra(android.content.Intent.EXTRA_TEXT, "This is tesing");

    startActivity(Intent.createChooser(i, "Share via"));
Run Code Online (Sandbox Code Playgroud)

从此我可以在任何社交媒体平台上分享文本.

但我想与此分享图像,我的图像是二进制形式.

InputStream input = new java.net.URL(
                                product.getString("url")).openStream();

 // Decode Bitmap
bitmap = BitmapFactory.decodeStream(input);
Run Code Online (Sandbox Code Playgroud)

所以图像共享我写了下面的代码:

i.putExtra(android.content.Intent.EXTRA_TEXT, bitmap);
Run Code Online (Sandbox Code Playgroud)

但它没有用.它分享如下文字: - android.graphics.Bitmap@43394c40

那么我怎样才能与此分享形象呢?

Nir*_*tel 5

  1. 首先,您必须下载该图像并保存在ExternalStorage中.检查此链接
  2. 社交应用不支持共享图像和文本.
  3. 请使用以下示例代码:

     Intent i = new Intent(android.content.Intent.ACTION_SEND);
     i.setType("image/*");
     i.putExtra(android.content.Intent.EXTRA_TEXT, "This is tesing");
     i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile("file_path"));
     startActivity(Intent.createChooser(i, "Share via"));
    
    Run Code Online (Sandbox Code Playgroud)

支持APP:

  1. Google+的

  2. 出去玩

  3. Gmail的
  4. 电子邮件
  5. WhatsApp的

不支持APP:

  1. Facebook的
  2. Skype的
  3. 远足