cari

Rumah  >  Soal Jawab  >  teks badan

java - 微信android sdk 能否一次发送多张图片?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

<code>WXImageObject imgObj = new WXImageObject();

imgObj.setImagePath(path);

 

WXMediaMessage msg = new WXMediaMessage();

msg.mediaObject = imgObj;

 

Bitmap bmp = BitmapFactory.decodeFile(path);

Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);

bmp.recycle();

msg.thumbData = Util.bmpToByteArray(thumbBmp, true);

 

SendMessageToWX.Req req = new SendMessageToWX.Req();

req.transaction = buildTransaction("img");

req.message = msg;

req.scene =  SendMessageToWX.Req.WXSceneTimeline ;

api.sendReq(req);

</code>

以上代码可以分享一张图片到微信朋友圈,但是如果 想要一次分享多张图片怎么办啊

ringa_leeringa_lee2842 hari yang lalu723

membalas semua(1)saya akan balas

  • 巴扎黑

    巴扎黑2017-04-17 11:16:34

    不能,至少目前这个SDK版本是不能处理多个图片。SDK没有混淆,通过观看,它支持

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    <code>public static final int TYPE_UNKNOWN = 0; 

    public static final int TYPE_TEXT = 1;

    public static final int TYPE_IMAGE = 2;

    public static final int TYPE_MUSIC = 3;

    public static final int TYPE_VIDEO = 4;

    public static final int TYPE_URL = 5;

    public static final int TYPE_FILE = 6;

    public static final int TYPE_APPDATA = 7;

    public static final int TYPE_EMOJI = 8;

    </code>

    SDK 通过Bundle来传递数据,用<key,value>记录每种数据类型,并且都是单条的记录,如图片数据 WXImageObject

    1

    2

    3

    4

    <code>paramBundle.putByteArray("_wximageobject_imageData", this.imageData);

    paramBundle.putString("_wximageobject_imagePath", this.imagePath);

    paramBundle.putString("_wximageobject_imageUrl", this.imageUrl);

    </code>

    只有单一的 imageData ,死心吧。

    不过,网上有个方法是通过系统的“分享”来调用微信,下面是我写的代码测试有效,不过这种方法还得手工在微信里面操作,适用范围太小:

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    <code>private void shareMultiplePictureToTimeLine(File... files) {

        Intent intent = new Intent();

        ComponentName comp = new ComponentName("com.tencent.mm",

                "com.tencent.mm.ui.tools.ShareToTimeLineUI");

        intent.setComponent(comp);

        intent.setAction(Intent.ACTION_SEND_MULTIPLE);

        intent.setType("image/*");

     

        ArrayList<Uri> imageUris = new ArrayList<Uri>();

        for (File f : files) {

            imageUris.add(Uri.fromFile(f));

        }

        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);

     

        startActivity(intent);

    }

     

                // 遍历 SD 卡下 .png 文件通过微信分享

                File root = Environment.getExternalStorageDirectory();

                File[] files = root.listFiles(new FileFilter() {

     

                    @Override

                    public boolean accept(File pathname) {

                        if (pathname.getName().endsWith(".png"))

                            return true;

                        return false;

                    }

                });

                shareMultiplePictureToTimeLine(files);

    </code>

    balas
    0
  • Batalbalas