2011-02-11 70 views
62

我希望我的应用程序用户能够向其他用户分享/推荐我的应用程序。我使用ACTION_SEND意图。我添加了纯文字,内容如下:安装这个很酷的应用程序。但是我找不到让用户直接进入市场安装屏幕的方法。我所能提供的只是一个网页链接或一些文本。 换句话说,我正在寻找一种非常直接的方式让android用户安装我的应用程序。在Android中分享应用程序“链接”

感谢您的帮助/指针,

托马斯

回答

153

这将让你从电子邮件,whastapp或其他任何选择。

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

托马斯,

您可能希望向用户提供一个链接,将带他们直接到您的应用程序的详细信息页面。以下是从developer.android.com:

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

在Android Market中,每个应用程序 有一个详细页面,为用户提供了应用程序的 概述。 例如,页面包括在使用中它的应用程序和屏幕截图 的简短描述 ,如果由 显影剂,以及从反馈用户 的信息和关于所述 显影剂供给。详细信息页面 包含一个“安装”按钮,用户可以触发该应用程序的下载/购买 。

如果你想给用户指 特定的应用程序,你的应用程序 可以采取用户直接 到应用程序的详细信息页面。要 这样做,你的应用程序发送包含以下格式的URI 和查询参数的 ACTION_VIEW意图:

市场://细节ID =

在这种情况下,包名 参数为目标应用程序的 完全限定的包名称,如 在包属性 中声明的 应用程序的清单文件中的清单元素。对于 例如:

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

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

+0

+1的链接。看起来不错。因为我希望用户分享,我仍然需要使用ACTION_SEND并在我的文本中添加市场链接。如果用户点击它,它会将他重定向到安装页面。听起来不错,我必须尝试。让我知道,如果我理解你的权利。 – Thomas 2011-02-11 20:06:44

+0

是的,您可以使用ACTION_SEND文本中的市场链接,但只有在Android设备上点击时才会起作用。 – 2011-02-11 20:56:21

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

,或者如果您想要从您的开发者分享您的其他应用程序。帐户你可以做这样的事情

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

要在应用程序名称和应用程序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:")); 
7

调用此方法:

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 Aap Ka Sewak App at: https://play.google.com/store/apps/details?id=" + appPackageName); 
    sendIntent.setType("text/plain"); 
    context.startActivity(sendIntent); 
} 
1

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

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")); 
2
标题为

共享应用程序是你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))); 
} 
1

最后这段代码是为我工作打开我们的Android的电子邮件客户端。 试试这个片段。

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

其实最好的方式来应用剪切您的用户之间,谷歌(火力)证明新技术的火力地堡动态链接通过几行,你可以把它 这是文档 https://firebase.google.com/docs/dynamic-links/ 和代码是

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 
         // ... 
        } 
       } 
      }); 
相关问题