在Android中分享应用程序"链接"

Tho*_*mas 90 android share

我希望我的应用程序用户能够与其他用户共享/推荐我的应用程序.我使用ACTION_SEND意图.我添加了纯文本,说明了以下内容:安装这个很酷的应用程序.但我找不到让用户直接进入市场安装界面的方法.我可以提供的只是一个网站链接或一些文字.换句话说,我正在寻找一个非常直接的方式让Android用户安装我的应用程序.

感谢您的帮助/指点,

托马斯

Ton*_*Ton 231

这将允许您选择电子邮件,whatsapp或其他.

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();
}   
Run Code Online (Sandbox Code Playgroud)

  • Android喜欢在更新中进行如此多的更改,以至于谁知道此代码在将来的更新中是否会失败 (2认同)

luk*_*jar 27

您也可以使用支持库中的ShareCompat类.

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

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

  • 请始终在链接中使用 https 而不是 http。 (3认同)

Wil*_*ate 20

托马斯,

您可能希望为用户提供一个market://链接,该链接会将他们直接带到您应用的详细信息页面.以下内容来自developer.android.com:

加载应用程序的"详细信息"页面

在Android Market中,每个应用程序都有一个"详细信息"页面,该页面提供用户应用程序的概述.例如,该页面包括应用程序的简短描述及其使用的屏幕截图(如果由开发人员提供),以及来自用户的反馈和有关开发人员的信息."详细信息"页面还包含一个"安装"按钮,用户可以触发下载/购买应用程序.

如果要将用户引用到特定应用程序,则应用程序可以将用户直接带到应用程序的"详细信息"页面.为此,您的应用程序发送一个ACTION_VIEW Intent,其中包含以下格式的URI和查询参数:

市场://细节ID =

在这种情况下,packagename参数是目标应用程序的完全限定包名称,如应用程序清单文件中manifest元素的package属性中声明的那样.例如:

市场://细节ID = com.example.android.jetboy

资料来源:http://developer.android.com/guide/publishing/publishing.html


Nil*_*hal 10

调用此方法:

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);
}
Run Code Online (Sandbox Code Playgroud)


OWA*_*DVL 9

更确切地说

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

或者如果你想从开发者那里分享你的其他应用程序.帐户你可以做这样的事情

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://play.google.com/store/apps/developer?id=Your_Publisher_Name"));
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)


Pha*_*inh 6

分享应用的标题是你的 app_name,内容是你的应用链接

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)));
}
Run Code Online (Sandbox Code Playgroud)


Ben*_*oot 5

要自动填写应用程序名称和应用程序ID,可以使用以下命令:

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:"));
Run Code Online (Sandbox Code Playgroud)


Ami*_*ske 5

我知道这个问题已经得到解答,但我想分享一个替代解决方案:

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"));
Run Code Online (Sandbox Code Playgroud)