【问题标题】:How to Share Entire Android App with Share Intent如何通过共享意图共享整个 Android 应用程序
【发布时间】:2012-12-18 20:37:39
【问题描述】:

我之前用过Sharing类型的intent,比如:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "---" });
intent.putExtra(Intent.EXTRA_SUBJECT, "---");
startActivity(Intent.createChooser(intent, "Contact Us!"));

但是,这基本上与电子邮件/彩信和其他文本或文档类型的应用程序共享。你如何做同样的事情,但包括 Facebook、Twitter 和 Google Plus 等社交分享(举出重要的名字)。我想分享的是这个应用程序,上面的文字说,“嘿,下载这个链接来看看这个应用程序!” (或类似的东西)。

【问题讨论】:

    标签: android android-intent sharing


    【解决方案1】:

    要添加 Facebook、Twitter 等共享选项,用户只需安装这些应用程序。由其他应用程序决定它们将告诉系统它们可以处理什么类型的Intents。

    然后一个基本的ACTION_SEND Intent 将被拾取。

    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT,
        "Hey check out my app at: https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID);
    sendIntent.setType("text/plain");
    startActivity(sendIntent);
    

    Source

    【讨论】:

    • 非常感谢。所以看来,仅仅通过在意图中包含文本(而不是空白文本正文),它会添加更多的社交选项?
    • 不,据我所知,这是“ACTION_SEND”和用户拥有可以处理“ACTION_SEND”的应用程序这一事实的结合。尝试空白文本(即不要“putExtra(..)”)并告诉我:D
    • 如果你看到我的问题,在那个例子中,我有ACTION_SEND 没有EXTRA_TEXT 并且只有电子邮件客户端、短信/彩信客户端、Google Drive 或我手机上的 Evernote 出现。虽然,我指定EXTRA_EMAIL 所以也许这就是为什么?
    【解决方案2】:

    如果你应用这个代码,那么它看起来像下面的图片

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, "My application name");
    intent.putExtra(Intent.EXTRA_TEXT, "This is my text");
    startActivity(Intent.createChooser(intent, "choose one"));
    

    ============================================= ==========================

    如果你应用这个代码,那么它看起来像下面的图片

    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("text/plain");
    sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
    startActivity(sendIntent);
    

    【讨论】:

      【解决方案3】:

      您可以通过使用共享意图来做到这一点

                  Intent shareIntent = new Intent(Intent.ACTION_SEND);
                  shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                  shareIntent.setType("text/plain");
                  shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hey, download this app!");
                  startActivity(shareIntent);     
      

      您可以将此意图放入 onclick 或在任何您想要的地方使用它

      我认为这回答了你的问题 =)

      【讨论】:

        【解决方案4】:

        在 Kotlin 中我们可以做到:

         private fun share(messageToShare: String, appUrl: String) {
            val intent = Intent(Intent.ACTION_SEND)
            intent.type = "text/plain"
            intent.putExtra(Intent.EXTRA_TEXT, messageToShare + appUrl)
            startActivity(Intent(intent))
        }
        

        【讨论】:

          【解决方案5】:

          在Intent.EXTRA_TEXT extra 中分享到 google play 的链接

          【讨论】:

            【解决方案6】:

            您还可以在分享应用时添加标题、主题和正文:

            Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
                            sharingIntent.setType("text/plain");
                            sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My App Name");
                            sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, getResources().getString(R.string.share_app_text));
                            startActivity(Intent.createChooser(sharingIntent, "Share app via"));
            

            【讨论】:

              【解决方案7】:

              试试这对我来说效果很好:

               Intent intent = new Intent();
                  intent.setAction(Intent.ACTION_SEND);
                  intent.putExtra(Intent.EXTRA_TEXT,"I suggest this app for you : https://play.google.com/store/apps/details?id=com.android.chrome");
                  intent.setType("text/plain");
                  startActivity(intent);
              

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2023-04-03
                • 2017-01-29
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多