Share application "link" in Android

AndroidShare

Android Problem Overview


I want my application user to be able to share/recommend my app to other users. I use the ACTION_SEND intent. I add plain text saying something along the lines of: install this cool application. But I can't find a way to enable users to directly go to the install screen of market place for instance. All I can provide them with is a web link or some text. In other words I am looking for a very direct way for android users to have my app installed.

Thanks for any help/pointers,

Thomas

Android Solutions


Solution 1 - Android

This will let you choose from email, whatsapp or whatever.

try { 
    Intent shareIntent = new Intent(Intent.ACTION_SEND);  
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, "My application name");
    String shareMessage= "\nLet me recommend you this application\n\n";
    shareMessage = shareMessage + "https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID +"\n\n";
    shareIntent.putExtra(Intent.EXTRA_TEXT, shareMessage);  
    startActivity(Intent.createChooser(shareIntent, "choose one"));
} catch(Exception e) { 
    //e.toString();
}	

Solution 2 - Android

You can use also ShareCompat class from support library.

ShareCompat.IntentBuilder.from(activity)
    .setType("text/plain")
    .setChooserTitle("Chooser title")
    .setText("http://play.google.com/store/apps/details?id=" + activity.getPackageName())
    .startChooser();

https://developer.android.com/reference/android/support/v4/app/ShareCompat.html

Solution 3 - Android

Thomas,

You would want to provide your users with a market:// link which will bring them directly to the details page of your app. The following is from developer.android.com:

> Loading an application's Details page > > In Android Market, every application > has a Details page that provides an > overview of the application for users. > For example, the page includes a short > description of the app and screen > shots of it in use, if supplied by the > developer, as well as feedback from > users and information about the > developer. The Details page also > includes an "Install" button that lets > the user trigger the download/purchase > of the application. > > If you want to refer the user to a > specific application, your > application can take the user directly > to the application's Details page. To > do so, your application sends an > ACTION_VIEW Intent that includes a URI > and query parameter in this format: > > market://details?id= > > In this case, the packagename > parameter is target application's > fully qualified package name, as > declared in the package attribute of > the manifest element in the > application's manifest file. For > example: > > market://details?id=com.example.android.jetboy

Source: http://developer.android.com/guide/publishing/publishing.html

Solution 4 - Android

Call this method:

public static void shareApp(Context context)
{
    final String appPackageName = context.getPackageName();
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, "Check out the App at: https://play.google.com/store/apps/details?id=" + appPackageName);
    sendIntent.setType("text/plain");
    context.startActivity(sendIntent);
}

Solution 5 - Android

To be more exact

   Intent intent = new Intent(Intent.ACTION_VIEW);
   intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.android.example"));
   startActivity(intent);

or 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);

Solution 6 - Android

To automatically fill in the application name and application id you could use this:

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:"));

Solution 7 - Android

Share application with title is you app_name, content is your application link

private static void shareApp(Context context) {
    final String appPackageName = BuildConfig.APPLICATION_ID;
    final String appName = context.getString(R.string.app_name);
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    String shareBodyText = "https://play.google.com/store/apps/details?id=" +
            appPackageName;
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, appName);
    shareIntent.putExtra(Intent.EXTRA_TEXT, shareBodyText);
    context.startActivity(Intent.createChooser(shareIntent, context.getString(R.string
            .share_with)));
}

Solution 8 - Android

I know this question has been answered, but I would like to share an alternate solution:

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
String shareSubText = "WhatsApp - The Great Chat App";
String shareBodyText = "https://play.google.com/store/apps/details?id=com.whatsapp&hl=en";
shareIntent.putExtra(Intent.EXTRA_SUBJECT, shareSubText);
shareIntent.putExtra(Intent.EXTRA_TEXT, shareBodyText);
startActivity(Intent.createChooser(shareIntent, "Share With"));

Solution 9 - Android

finally, this code is worked for me to open the email client from android device. try this snippet.

Intent testIntent = new Intent(Intent.ACTION_VIEW);
                    Uri data = Uri.parse("mailto:?subject=" + "Feedback" + "&body=" + "Write Feedback here....." + "&to=" + "[email protected]");
                    testIntent.setData(data);
                    startActivity(testIntent);

Solution 10 - Android

Kotlin extension for share action. You can share whatever you want e.g. link

fun Context.share(text: String) =
    this.startActivity(Intent().apply {
        action = Intent.ACTION_SEND
        putExtra(Intent.EXTRA_TEXT, text)
        type = "text/plain"
    })

Usage

context.share("Check https://stackoverflow.com")

Solution 11 - Android

According to official docs in 2021 preferred way is

fun shareTextToOtherApps(message: String) {
        val sendIntent: Intent = Intent().apply {
            action = Intent.ACTION_SEND
            putExtra(Intent.EXTRA_TEXT, message)
            type = "text/plain"
        }

        val shareIntent = Intent.createChooser(sendIntent, null)
        startActivity(shareIntent)
    }

Solution 12 - Android

Actually the best way to sheared you app between users , google (firebase) proved new technology Firebase Dynamic Link Through several lines you can make it this is documentation https://firebase.google.com/docs/dynamic-links/ and the code is

  Uri dynamicLinkUri = dynamicLink.getUri();
      Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance().createDynamicLink()
            .setLink(Uri.parse("https://www.google.jo/"))
            .setDynamicLinkDomain("rw4r7.app.goo.gl")
            .buildShortDynamicLink()
            .addOnCompleteListener(this, new OnCompleteListener<ShortDynamicLink>() {
                @Override
                public void onComplete(@NonNull Task<ShortDynamicLink> task) {
                    if (task.isSuccessful()) {
                        // Short link created
                        Uri shortLink = task.getResult().getShortLink();
                        Uri flowchartLink = task.getResult().getPreviewLink();
                        Intent intent = new Intent();
                        intent.setAction(Intent.ACTION_SEND);
                        intent.putExtra(Intent.EXTRA_TEXT,  shortLink.toString());
                        intent.setType("text/plain");
                        startActivity(intent);
                    } else {
                        // Error
                        // ...
                    }
                }
            });

Solution 13 - Android

@Linh answer is almost good but causing a crash because of the missing FLAG_ACTIVITY_NEW_TASK, here is what worked for me

    public static void shareApp(Context context) {
    final String appPackageName = context.getPackageName();
    Intent sendIntent = new Intent();
    sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, "Check out the App at: https://play.google.com/store/apps/details?id=" + appPackageName);
    sendIntent.setType("text/plain");
    context.startActivity(sendIntent);
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionThomasView Question on Stackoverflow
Solution 1 - AndroidTonView Answer on Stackoverflow
Solution 2 - AndroidlukjarView Answer on Stackoverflow
Solution 3 - AndroidWill TateView Answer on Stackoverflow
Solution 4 - AndroidNileshView Answer on Stackoverflow
Solution 5 - AndroidOWADVLView Answer on Stackoverflow
Solution 6 - AndroidBen GrootView Answer on Stackoverflow
Solution 7 - AndroidLinhView Answer on Stackoverflow
Solution 8 - AndroidAmit MhaskeView Answer on Stackoverflow
Solution 9 - AndroidKishankumar VasoyaView Answer on Stackoverflow
Solution 10 - AndroidtomrozbView Answer on Stackoverflow
Solution 11 - AndroidZohab AliView Answer on Stackoverflow
Solution 12 - AndroidahmadView Answer on Stackoverflow
Solution 13 - AndroidShahid GhafoorView Answer on Stackoverflow