Share image and text through Whatsapp or Facebook

前端 未结 12 908
谎友^
谎友^ 2020-11-28 05:23

I have in my app a share button and i want to share an image and a text at the same time. In GMail it works fine but in WhatsApp, only the image is sent and in Facebook the

12条回答
  •  执念已碎
    2020-11-28 06:01

    Actually. it is possible to send image and text through WhatsApp by downloading the image to device external storage and then share the image to WhatsApp.

    if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
    
        Bitmap bm = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        Intent intent = new Intent(Intent.ACTION_SEND);
        String share_text = "image and text";
        intent.putExtra(Intent.EXTRA_TEXT, notification_share);
        String path = MediaStore.Images.Media.insertImage(MainActivity.this.getContentResolver(), bm, "", null);
        Uri screenshotUri = Uri.parse(path);
    
        intent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
        intent.setType("image/*");
        startActivity(Intent.createChooser(intent, "Share image via..."));
    } else {
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
    }
    //The above code works perfect need to show image in an imageView
    

提交回复
热议问题