How do create whatsapp share option in my app
Clash Royale CLAN TAG#URR8PPP
How do create whatsapp share option in my app
I am new to Android development. I don't know Android Studio and Java. But I am developing an app with the help of Google, YouTube and StackOverflow. Now I want to add share option (Image + text) in my Recyclerview
image to Whatsapp.
Recyclerview
The image is loaded from Firebase
storage using Picasso
lib. I don't know how to convert Firebase ImageView
to bitmap
.
Firebase
Picasso
Firebase ImageView
bitmap
I have added a Share button below each item. How do I create share option in this sharebutton?
This is my MainActivity:
public class ReviewMainActivity extends AppCompatActivity
private static final String APP_ID = "ca-app-pub-8867939169855032~3069406037";
FirebaseDatabase database;
DatabaseReference MCR;
RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
FirebaseRecyclerAdapter<ReviewModel, ReviewViewHolder> adapter;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_review_main);
Toolbar toolbar = findViewById(R.id.ReviewMain_Toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(null);
toolbar.setLogo(R.mipmap.uploadpost);
toolbar.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
Intent settingsIntent = new Intent(ReviewMainActivity.this, ReviewPostUploadActivity.class);
startActivity(settingsIntent);
);
if (getSupportActionBar()!=null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
MobileAds.initialize(this,APP_ID);
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
database = FirebaseDatabase.getInstance();
MCR = database.getReference("Review");
recyclerView = (RecyclerView)findViewById(R.id.recycler_ReviewMain);
recyclerView.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setReverseLayout(true);
layoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager (layoutManager);
loadMenu();
private void loadMenu()
adapter = new FirebaseRecyclerAdapter<ReviewModel, ReviewViewHolder>(ReviewModel.class,
R.layout.review_main_items,
ReviewViewHolder.class,MCR)
@Override
protected void populateViewHolder(ReviewViewHolder viewHolder, ReviewModel model, final int position)
viewHolder.Review_Title.setText(model.getTitle());
viewHolder.Profile_Name.setText(model.getProfileName());
Picasso.with(getBaseContext()).load(model.getImage())
.into(viewHolder.Review_Image);
Picasso.with(getBaseContext()).load(model.getProfileimage())
.into(viewHolder.Profile_Image);
final ReviewModel local = model;
viewHolder.Share_Icon.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
);
;
recyclerView.setAdapter(adapter);
@Override
public boolean onOptionsItemSelected(MenuItem item)
if (item.getItemId()==android.R.id.home)
finish();
return super.onOptionsItemSelected(item);
This is my Intent Part
Intent shareIntent;
Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher);
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+"/Share.png";
OutputStream out = null;
File file=new File(path);
try
out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
catch (Exception e)
e.printStackTrace();
path=file.getPath();
Uri bmpUri = Uri.parse("file://"+path);
shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.putExtra(Intent.EXTRA_TEXT,"Hey please check this application " + "https://play.google.com/store/apps/details?id=" +getPackageName());
shareIntent.setType("image/png");
startActivity(Intent.createChooser(shareIntent,"Share with"));
oh sorry i want share image+text
– Prasin Prathap
Aug 8 at 8:41
Go ahead and try this Dharmesh rughani's answer: stackoverflow.com/questions/20333186/… . Let me know if you still find it difficult.
– impossible
Aug 8 at 8:55
just tried but image didnt load in share option. My imageview load from Firebase. how to convert imageview in to bitmap.
– Prasin Prathap
Aug 8 at 9:42
can you try:
try URL url = new URL("http://...."); Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream()); catch(IOException e) System.out.println(e);
– impossible
Aug 8 at 9:50
try URL url = new URL("http://...."); Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream()); catch(IOException e) System.out.println(e);
1 Answer
1
You can try
Intent uriIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("whatsapp://send?text=" + "Text you want to share"));
startActivity(uriIntent);
This will open whatsapp and will ask you for the people you want to send the entered text to.
To send a file do this
File outputFile = new File(Environment.getExternalStoragePublicDirectory
(Environment.DIRECTORY_DOWNLOADS), "example.pdf");
Uri uri = Uri.fromFile(outputFile);
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setType("application/pdf");
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setPackage("com.whatsapp");
activity.startActivity(share);
The above code will send pdf files.
To send the image (one image) , replace “application/pdf” with “image/*”
Remember : application will crash if you try to send text, pdf and image all at the same time, so send only one item at a time.
Thanks brother. Text sharing working perfectly. but i want to share image also. how to send image.
– Prasin Prathap
Aug 8 at 13:24
I have updated the answer to send a pdf file
– Jaswant Singh
Aug 8 at 14:08
Also added for the image
– Jaswant Singh
Aug 8 at 14:25
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
So you want to share image/ text/ or (image+text)?
– impossible
Aug 8 at 8:31