如何将多张图片分享到WhatsApp应用程序?



如何将多张图像共享到所有共享应用程序,例如(WhatsApp,电子邮件(,但是当我尝试将多张图像共享到WhatsApp时,我收到消息为:sharing failed, please try again。我更改setType但不起作用 请查看此链接

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

请检查以下代码:

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

我在网址中传递图像,当单击按钮时,所有图像都在WhatsApp上共享。

请帮忙。

像Android上的大多数社交应用程序一样,WhatsApp会监听共享媒体和文本的意图。例如,只需创建一个共享文本的意图,系统选择器就会显示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);

但是,如果您希望直接共享到 WhatsApp 并绕过系统选择器,您可以通过在您的意图中使用 setPackage 来实现:

sendIntent.setPackage("com.whatsapp");

这将只是在你调用开始活动(发送意图(之前设置的;

最新更新