Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sending both text and image on WhatsApp in Android Studio

I want to send both text and image on whats-app in android studio but i don’t have any idea. I am very new to android and need help to complete a project of my college.
Help me to complete the project.

I have no idea about this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should do some practice first to learn. Anyway Use the given code to send data and image together on Whats App. Use an image box, edit text box, file location, etc. to use the code.

        share.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) 
    imageView.getDrawable();
        Bitmap bitmap = bitmapDrawable.getBitmap();
        shareImageandText(bitmap);
    }
});
    }
    private void shareImageandText(Bitmap bitmap) {
Uri uri = getmageToShare(bitmap);
Intent intent = new Intent(Intent.ACTION_SEND);

// putting uri of image to be shared
intent.putExtra(Intent.EXTRA_STREAM, uri);

// adding text to share
intent.putExtra(Intent.EXTRA_TEXT, s5.getText().toString());

// setting type to image
intent.setType("image/png");

// calling startactivity() to share
startActivity(Intent.createChooser(intent, "Share Via"));
   }

    private Uri getmageToShare(Bitmap bitmap) {
File imagefolder = new File(getCacheDir(), "images");
Uri uri = null;
try {
    imagefolder.mkdirs();
    File file = new File(imagefolder, "shared_image.png");
    FileOutputStream outputStream = new FileOutputStream(file);
    bitmap.compress(Bitmap.CompressFormat.PNG, 90, outputStream);
    outputStream.flush();
    outputStream.close();
    uri = FileProvider.getUriForFile(this, 
    "com.niky.sample.fileprovider", file);
} catch (Exception e) {
    Toast.makeText(this, "" + e.getMessage(), Toast.LENGTH_LONG).show();
}
return uri;
    }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading