0

Hi I am new to develop application in android. I saw other apps, they use share to friends with Messenger, or Facebook.. for instant, I share it to Messenger, then in the content should show some texts and the link of app!! How can I do that? anyone please help!!! I have tried the answer in this site to share, but it works only with SMS and Gmail, but if I share to Messenger, it shows nothing!

1 Answers1

0

Try this code for sharing drawable image with link and text.

Follow this steps

Step 1 :- Take one button in your layout.xml for sharing your content.

Step 2 :- set onClickListner for this button in your Activity.java.

Step 3 :- Put this code to your Activity.java file Button setOnClickListner.

String myText = "share text though this string";
            Bitmap icon = BitmapFactory.decodeResource(getResources(),
                    R.mipmap.icon_256);
            Intent share = new Intent(Intent.ACTION_SEND);
            share.setType("image/jpg");
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
            File f = new File(Environment.getExternalStorageDirectory()
                    + File.separator + "temporary_file.jpg");
            try {
                f.createNewFile();
                FileOutputStream fo = new FileOutputStream(f);
                fo.write(bytes.toByteArray());
            } catch (IOException e) {
                e.printStackTrace();
            }
            String extraText = myText + "\n\nhttps://www.google.co.in";
            share.putExtra(Intent.EXTRA_TEXT,extraText);
            share.putExtra(Intent.EXTRA_STREAM,
                    Uri.fromFile(f));
            startActivity(Intent.createChooser(share, "Share Image"));
Vishal Senjaliya
  • 454
  • 6
  • 21
  • Thank you so much!!! but I still wonder if I possibly create Image from my app to the folder on Storage of the Phone, then share it by fetch the uri of it. how can i do that? – Sopheap SK Dec 14 '16 at 03:47