5

In my app i have to add an intent to share my app. I looked through Tez, which shares the app icon along with a text which contains a hyperlink. How to achieve this?enter image description here

Manoj Perumarath
  • 9,337
  • 8
  • 56
  • 77

11 Answers11

3

you can try this one..

    Uri uri = Uri.fromFile(imageFile);
    Intent intent1 = new Intent();
    intent1.setAction(Intent.ACTION_SEND);
    intent1.setType("image/*");
    intent1.putExtra(android.content.Intent.EXTRA_SUBJECT, "App Name");
    intent1.putExtra(Intent.EXTRA_TEXT, "Download the app from google play store now - "+ APP_STORE_URL);
    intent1.putExtra(Intent.EXTRA_STREAM, uri);
    try {
        startActivity(Intent.createChooser(intent1, "Share"));
    } catch (ActivityNotFoundException e) {
        Toast.makeText(getContext(), "please try again", Toast.LENGTH_SHORT).show();
    }

this will works : put image file and text box in share intent

Janku
  • 238
  • 2
  • 10
1

It look like you want to create an referrer links for which try using this firebase service.Once you have got your referrer URL ready.Create an intent as follow to share it.

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subjectText);
shareIntent.putExtra(Intent.EXTRA_HTML_TEXT, "Hey!Checkout this app "+ APP_STORE_URL); 
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(shareIntent, "Invite Friends"));

**Note:**If you are using dynamic links you can add your app icon in the social meta tags param

Community
  • 1
  • 1
Abilash
  • 313
  • 5
  • 15
1

Try this

Uri imageUri = Uri.parse("android.resource://" + getPackageName() + "/drawable/" + "ic_launcher");
Intent shareIntent = new Intent(); 
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello" + REFERRAL_URL);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "send"));`
Nadeem M
  • 11
  • 2
1

Copy this code into your toolbar/menu

    try {
    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("text/plain");
    i.putExtra(Intent.EXTRA_SUBJECT, "Your Subject");
    String text = "\nYour description";
    text = text + "https://play.google.com/store/apps/details?id=apppackagename \n\n";
    i.putExtra(Intent.EXTRA_TEXT, text);
    startActivity(Intent.createChooser(i, "Choose "));
    } 
    catch(Exception e) {
    //e.toString();
}
Akshay Katariya
  • 1,464
  • 9
  • 20
vrie
  • 446
  • 4
  • 8
1
Intent share = new Intent(Intent.ACTION_SEND);
    share.setType("image/jpeg");

    /**This is the image to share**/
    Bitmap icon = BitmapFactory.decodeResource(getResources(),
            R.drawable.ic_launcher);

    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.TITLE, "title");
    values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
    Uri uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            values);


    OutputStream outstream;
    try {
        outstream = getContentResolver().openOutputStream(uri);
        icon.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
        outstream.close();
    } catch (Exception e) {
        System.err.println(e.toString());
    }

    share.putExtra(Intent.EXTRA_STREAM, uri);
    share.putExtra(Intent.EXTRA_TEXT, "YOUR_BODY_TEXT_HERE");
    startActivity(Intent.createChooser(share, "Share Image"));

I've tested the above code, it works as per your requirement.

PS: You need to have WRITE_EXTERNAL_STORAGE permission. Be sure to include it and handle it according to SDK's.

Balraj
  • 328
  • 2
  • 7
1

This code will share both the files together

    ArrayList<Uri> myFilesUriList = new ArrayList<>(); 
    myFilesUriList.add(); // add your image path as uri
    myFilesUriList.add(); // add your text file path as uri

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND_MULTIPLE);

    intent.setType("image/*");
    intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, myFilesUriList);
    startActivity(intent);
 This code will share both the files Separately
First share the file then on Activity Result, share text Separately
        ArrayList<Uri> uriArrayList = new ArrayList<>();
        uriArrayList.add(); // add your image path as uri

        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SEND_MULTIPLE);
        intent.setType("image/*");
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriArrayList);
        startActivityForResult(intent, 156);

        @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 156) {
            Intent sharingIntent = new Intent(Intent.ACTION_SEND);
            sharingIntent.setType("text/*");
            sharingIntent.putExtra(Intent.EXTRA_SUBJECT, ""); //"Subject here"
            sharingIntent.putExtra(Intent.EXTRA_TEXT, "shareBody ");
            sharingIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            startActivity(Intent.createChooser(sharingIntent, "Share text via.."));

        }
    }
jessica
  • 1,700
  • 1
  • 11
  • 17
1

It's URL Meta Data. These meta data is returned as response from server.

<meta property="og:site_name" content="San Roque 2014 Pollos">
<meta property="og:title" content="San Roque 2014 Pollos" />
<meta property="og:description" content="Programa de fiestas" />
<meta property="og:image" itemprop="image" content="http://pollosweb.wesped.es/programa_pollos/play.png">
<meta property="og:type" content="website" />
<meta property="og:updated_time" content="1440432930" />

Showing Thumbnail for link in WhatsApp || og:image meta-tag doesn't work

1

Step 1 - Read the image which you want to share Step 2 - Store that image in your external storage Step 3 - share via intent

// Extract Bitmap from ImageView drawable
Drawable drawable = ContextCompat.getDrawable(this, R.mipmap.launcher); // your image
if (drawable instanceof BitmapDrawable) {
    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();

    // Store image to default external storage directory
    Uri bitmapUri = null;
    try {
        File file = new File(Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_DOWNLOADS), "share_image_" + System.currentTimeMillis() + ".png");
        file.getParentFile().mkdirs();
        FileOutputStream out = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
        out.close();
        bitmapUri = Uri.fromFile(file);
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (bitmapUri != null) {
        Intent shareIntent = new Intent();
        shareIntent.putExtra(Intent.EXTRA_TEXT, "I am inviting you to join our app. A simple and secure app developed by us. https://www.google.co.in/");
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_STREAM, bitmapUri);
        shareIntent.setType("image/*");
        startActivity(Intent.createChooser(shareIntent, "Share my app"));
    }
}

Note - Add WRITE_EXTERNAL_STORAGE permission in your manifest. Ask runtime permission on Android 6.0 and higher.

Chandra Sharma
  • 1,339
  • 1
  • 12
  • 26
1

You might be looking for deep linking to your app

https://developer.android.com/training/app-links/index.html

https://developer.android.com/training/app-links/deep-linking.html

Or if you want links to your app across platforms you can check out Firebase dynamic links https://firebase.google.com/docs/dynamic-links/

AbdulAli
  • 555
  • 3
  • 9
1
private void prepareShareIntent(Bitmap bmp) {
        Uri bmpUri = getLocalBitmapUri(bmp); // see previous remote images section
        // Construct share intent as described above based on bitmap

        Intent shareIntent = new Intent();
        shareIntent = new Intent();
        shareIntent.setPackage("com.whatsapp");
        shareIntent.setAction(Intent.ACTION_SEND);

        shareIntent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.share_app)  );
        shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
        shareIntent.setType("image/*");
        shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivity(Intent.createChooser(shareIntent, "Share Opportunity"));

    }

private Uri getLocalBitmapUri(Bitmap bmp) {
        Uri bmpUri = null;
        File file = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "share_image_" + System.currentTimeMillis() + ".png");
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(file);
            bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            bmpUri = Uri.fromFile(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return bmpUri;
    }
Blue_Alien
  • 2,148
  • 2
  • 25
  • 29
0

Try this code:

int applicationNameId = context.getApplicationInfo().labelRes;
final String appPackageName = context.getPackageName();
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT, activity.getString(applicationNameId));
String text = "Install this cool application: ";
String link = "https://play.google.com/store/apps/details?id=" + appPackageName;
i.putExtra(Intent.EXTRA_TEXT, text + " " + link);
startActivity(Intent.createChooser(i, "Share link:"));

if you want to share your other apps from your dev. account you can do something like this

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://play.google.com/store/apps/developer? 
id=Your_Publisher_Name"));
startActivity(intent);
Arun J
  • 687
  • 4
  • 14
  • 27