【问题标题】:Open Activity with Linkify Android使用 Linkify Android 打开 Activity
【发布时间】:2014-09-02 18:12:07
【问题描述】:

我想在用户点击带有 linkify 的 textView 时打开 Activity... 这是我的代码:

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

 <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 时,会抛出以下异常:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://Solution.Project.welcomeactivity (has extras) }

【问题讨论】:

    标签: java android android-intent android-activity android-xml


    【解决方案1】:

    您的意图过滤器应如下所示:

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

    您缺少 data 标记,如下所示

    scheme 可以是 http 或您自己定制的。

    host 是链接,例如 xyz.com

    pathPrefix 是可选的,例如 /homepage

     <data android:scheme="content"
              android:host="Solution.Project.WelcomeActivity" />
    

    阅读android Documentation for Deep Linking

    【讨论】:

      【解决方案2】:

      你必须在你的活动中使用provider标签并匹配authority

      【讨论】:

      猜你喜欢
      • 2016-12-05
      • 1970-01-01
      • 1970-01-01
      • 2018-08-02
      • 2015-06-29
      • 2015-12-11
      • 1970-01-01
      • 2020-12-19
      相关资源
      最近更新 更多