简体   繁体   English

如何将多个图像共享到whatsapp应用程序?

[英]how to share multiple images to whatsapp app?

How to share multiple images to all share apps like (WhatsApp, email) but when I try share multiple images to WhatsApp, I got message as : sharing failed, please try again . 如何将多个图像共享到所有共享的应用程序(如WhatsApp,电子邮件),但是当我尝试将多个图像共享到WhatsApp时,出现如下消息: sharing failed, please try again I change setType but not working please check this link 我更改了setType但无法正常工作,请检查此链接

https://trinitytuts.com/share-multiple-images-to-whatsapp-or-another-app-android/ https://trinitytuts.com/share-multiple-images-to-whatsapp-or-another-app-android/

Please check below code : 请检查以下代码:

imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //imageUriArray = new ArrayList<Uri>();
            toolbar.setVisibility(View.GONE);

            for (int i = 0; i < arrayList.size(); i++) {
                Date now = new Date();
                android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
                aa = screenWidth * i;
                horizontal.scrollTo(aa, 0);


                try {
                    // image naming and path  to include sd card  appending name you choose for file
                    String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + i + ".jpg";

                    // create bitmap screen capture
                    View v1 = myView.getRootView();
                    v1.setDrawingCacheEnabled(true);
                    Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
                    v1.setDrawingCacheEnabled(false);

                    File imageFile = new File(mPath);

                    FileOutputStream outputStream = new FileOutputStream(imageFile);
                    int quality = 100;
                    bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
                    outputStream.flush();
                    outputStream.close();
                    imageUriArray.add(Uri.fromFile(new File(String.valueOf(imageFile))));
                    //openScreenshot(imageFile);
                } catch (Throwable e) {
                    // Several error may come out with file handling or OOM
                    e.printStackTrace();
                }
            }
            toolbar.setVisibility(View.VISIBLE);
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUriArray);
            intent.setType("image/jpeg");
            startActivity(intent);
        }
    });

    arrayList = new ArrayList<>();
    arrayList.add("https://trinitytuts.com/wp-content/uploads/2015/02/trinitylogo.png");
    arrayList.add("http://lh4.googleusercontent.com/-1hHevfC4VTQ/AAAAAAAAAAI/AAAAAAAAAGs/Bi_dipj31f4/photo.jpg?sz=104");

    for (int ii = 0; ii < arrayList.size(); ii++) {
        LayoutInflater inflaters = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        myView = inflaters.inflate(R.layout.pager_item_multi, null);
        layMain = (LinearLayout) myView.findViewById(R.id.layMain);
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        //int screenHeight = metrics.heightPixels;
        screenWidth = metrics.widthPixels;
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(screenWidth, LinearLayout.LayoutParams.MATCH_PARENT);
        ImageView imageViews = (ImageView) myView.findViewById(R.id.img_pager_item);
        Picasso.with(this).load(arrayList.get(ii)).placeholder(R.mipmap.ic_launcher).into(imageViews);
        layMain.setLayoutParams(layoutParams);
        layMain.setTag("" + ii);
        layout.addView(myView);
    }
}

I pass Images in url and when click on button all images share on WhatsApp. 我在URL中传递图像,然后单击按钮,所有图像都在WhatsApp上共享。

Please help. 请帮忙。

Like most social apps on Android, WhatsApp listens to intents to share media and text. 与Android上的大多数社交应用程序一样,WhatsApp会听取共享媒体和文本的意图。 Simply create an intent to share text, for example, and WhatsApp will be displayed by the system picker: 例如,只需创建一个共享文本的意图,系统选择器就会显示WhatsApp:

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Your image url here.");
sendIntent.setType("text/plain");
startActivity(sendIntent);

However, if you prefer to share directly to WhatsApp and bypass the system picker, you can do so by using setPackage in your intent: 但是,如果您希望直接共享给WhatsApp并绕过系统选择器,则可以通过使用setPackage来实现:

sendIntent.setPackage("com.whatsapp");

This would simply be set right before you call startActivity(sendIntent); 只需在调用startActivity(sendIntent);之前设置即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM