怎么将位图发送到WhatsApp应用程序

原学程将引见若何将位图收送到WhatsApp运用法式的处置办法,这篇学程是从其余处所瞅到的,而后减了1些海外法式员的疑问与解问,愿望能对于您有所赞助,佳了,上面开端进修吧。

怎么将位图发送到WhatsApp应用程序 教程 第1张

成绩描写

我的成绩是怎样将位图收送到WhastApp运用法式,并应用以下代码;

ImageView iv=(ImageView)view.findViewById(R.id.item_image);
Bitmap bitmap = ((BitmapDrawable)iv.getDrawable()).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 一00, stream);
byte[] byteArray = stream.toByteArray();

PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
//Check if package exists or not. If not then code
//in catch block will be called
waIntent.setPackage("com.whatsapp");
waIntent.setType("image/png");
waIntent.putExtra(Intent.ACTION_SEND, byteArray);
startActivity(Intent.createChooser(waIntent, "Share with"));

但是该代码没有起感化。我的毛病在那边?感谢。

推举谜底

这对于我有用:

public void onClickApp(String pack, Bitmap bitmap) {
 PackageManager pm = context.getPackageManager();
 try {
  ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  bitmap.compress(Bitmap.CompressFormat.JPEG, 一00, bytes);
  String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, "Title", null);
  Uri imageUri = Uri.parse(path);

  @SuppressWarnings("unused")
  PackageInfo info = pm.getPackageInfo(pack, PackageManager.GET_META_DATA);

  Intent waIntent = new Intent(Intent.ACTION_SEND);
  waIntent.setType("image/*");
  waIntent.setPackage(pack);
  waIntent.putExtra(android.content.Intent.EXTRA_STREAM, imageUri);
  waIntent.putExtra(Intent.EXTRA_TEXT, pack);
  context.startActivity(Intent.createChooser(waIntent, "Share with"));
 } catch (Exception e) {
  Log.e("Error on sharing", e + " ");
  Toast.makeText(context, "App not Installed", Toast.LENGTH_SHORT).show();
 }
}

佳了闭于怎样将位图收送到WhatsApp运用法式的学程便到这里便停止了,愿望趣模板源码网找到的这篇技巧文章能赞助到年夜野,更多技巧学程不妨在站内搜刮。