首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Linkify Android打开活动

使用Linkify Android打开活动
EN

Stack Overflow用户
提问于 2014-09-02 18:12:07
回答 2查看 1.6K关注 0票数 2

我想打开活动时,用户点击textView与链接.这是我的代码:

代码语言:javascript
复制
Pattern tagMatcher = Pattern.Compile("#([A-Za-z0-9_-]+)");

            //Scheme for Linkify, when a word matched tagMatcher pattern,
            //that word is appended to this URL and used as content URI
            String newActivityURL = "content://Solution.Project.WelcomeActivity";
            //Attach Linkify to TextView
            wrapper.Text.Text = post.PostText;
            Linkify.AddLinks(wrapper.Text, tagMatcher, newActivityURL);

还有我的安卓manifest.xml

代码语言:javascript
复制
 <application android:icon="@drawable/Icon" android:label="Welcome">
    <activity android:name=".WelcomeActivity" android:label="@string/WelcomeText">
        <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>
    </activity>
 </application>

当用户单击textView时,它会引发以下异常:

代码语言:javascript
复制
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://Solution.Project.welcomeactivity (has extras) }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-09-16 12:09:43

您的意图筛选器应该如下所示:

代码语言:javascript
复制
   <intent-filter android:label="@string/filter_title_viewgizmos">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
    <data android:scheme="content"
          android:host="Solution.Project.WelcomeActivity" />

</intent-filter>

您缺少了数据标记,如下所示

方案可以是http,也可以是您自己的自定义方案。

主机是链接,如xyz.com

pathPrefix与/homepage一样是可选的。

代码语言:javascript
复制
 <data android:scheme="content"
          android:host="Solution.Project.WelcomeActivity" />

读取用于深度链接的android文档

票数 2
EN

Stack Overflow用户

发布于 2014-09-02 18:18:26

您必须在您的活动中使用provider标记与authority匹配。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25629691

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档