搜尋

首頁  >  問答  >  主體

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

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

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

ringa_leeringa_lee2831 天前714

全部回覆(1)我來回復

  • 巴扎黑

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

    不能,至少目前這個SDK版本是不能處理多個圖片。 SDK沒有混淆,透過觀看,它支援

    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;
    

    SDK 透過Bundle來傳遞數據,用<key,value>記錄每種數據類型,並且都是單一的記錄,如圖片數據WXImageObject :< /p>

    paramBundle.putByteArray("_wximageobject_imageData", this.imageData);
    paramBundle.putString("_wximageobject_imagePath", this.imagePath);
    paramBundle.putString("_wximageobject_imageUrl", this.imageUrl);
    

    只有單一的 imageData ,死心吧。

    不過,網路上有個方法是透過系統的「分享」來呼叫微信,以下是我寫的程式碼測試有效,不過這種方法還得手工在微信裡面操作,適用範圍太小:

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

    回覆
    0
  • 取消回覆