Share image and text through Whatsapp or Facebook

前端 未结 12 935
谎友^
谎友^ 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条回答
  •  旧时难觅i
    2020-11-28 05:44

    This works:

        
            
                
                
                
                
                
            
        
    
            soru_image = (ImageView) soruView.findViewById(R.id.soru_image);
           soru_image.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    try {
                        v.buildDrawingCache();
                        Bitmap bitmap =   v.getDrawingCache();
                        String root = Environment.getExternalStorageDirectory().toString();
                        File myDir = new File(root + "/SoruCevap");
                        Random generator = new Random();
                        int n = 10000;
                        n = generator.nextInt(n);
                        String fname = "Image-" + n + ".jpg";
                        File file = new File(myDir, fname);
                        if (file.exists()) file.delete();
                        try {
                            FileOutputStream out = new FileOutputStream(file);
                            bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
                            out.flush();
                            out.close();
                        } catch (Exception ex) {
                            //ignore
                        }
                        Intent waIntent = new Intent(Intent.ACTION_SEND);
                        waIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                        waIntent.setType("image/*");
                        waIntent.setPackage("com.whatsapp");
                        waIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.fromFile(file));
                        getContext().startActivity(Intent.createChooser(waIntent, "Share with"));
                    } catch (Exception e) {
                        Log.e("Error on sharing", e + " ");
                        Toast.makeText(getContext(), "App not Installed", Toast.LENGTH_SHORT).show();
                    }
    

提交回复
热议问题