【问题标题】:Android: How i can share a link and open an activity when user click on this linkAndroid:当用户单击此链接时,我如何共享链接并打开活动
【发布时间】:2016-04-28 18:26:59
【问题描述】:

我想让用户能够与其他人共享他们的对象。
我有一个活动,可以使用这样的意图过滤器显示对象信息:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="http" android:host="www.mywebsite.com" />
</intent-filter>

分享代码:

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Constants.EXTRA_OBJECT_ID, id);
shareIntent.putExtra(Constants.EXTRA_IS_LOCAL, false);
shareIntent.putExtra(Intent.EXTRA_TEXT, "http://www.mywebsite.com");
startActivity(Intent.createChooser(shareIntent, "Share link using"));

但是当我点击此链接时,我无法在“使用完成操作”对话框中看到我的应用程序。

【问题讨论】:

    标签: android android-intent intentfilter


    【解决方案1】:

    当前您尝试发送/共享链接,但您在清单中添加了意图过滤器以供查看。因此,对于查看,您应该将意图操作设置为查看,然后尝试。像这样:

    Intent shareIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.mywebsite.com"));
    

    这是因为您添加了视图类别的意图过滤器,即:

    <action android:name="android.intent.action.VIEW" />
    

    如果您想分享链接,请在 Intent 过滤器中添加 SEND 类别,如下所示:

    <action android:name="android.intent.action.SEND"/>
    

    我认为这对你会有帮助!

    【讨论】:

    • 我想先将链接作为文本分享,然后在用户点击此链接时打开活动
    猜你喜欢
    • 2017-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-16
    • 1970-01-01
    • 2019-02-20
    • 2016-02-07
    相关资源
    最近更新 更多