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