【问题标题】:Links with custom uri scheme does not work from TextView带有自定义 uri 方案的链接在 TextView 中不起作用
【发布时间】:2015-11-24 11:28:21
【问题描述】:

我正在尝试在我的应用程序中打开一组特定的活动,为此我在我的 AndroidManifest 文件中添加了一个自定义 uri 方案。

这里的问题是,当我在 TextView 中使用这些链接时,出现以下异常:

android.content.ActivityNotFoundException:找不到要处理的活动 意图 { act=android.intent.action.VIEW dat=numbers://imnumbers.com/buynumber(有附加)}

从 WebView(在 WebView 中单击链接)时,一切正常。我在网上广泛搜索了一个无济于事的解决方案。

这就是我为 TextView 解析 html 的方式:

textView.setText(Html.fromHtml(message.getContent()));
textView.content.setMovementMethod(LinkMovementMethod.getInstance());

我试过this answer,但它不起作用。当我点击链接时没有任何反应。

更新: 自定义uri方案定义如下:

    <activity
        android:name=".simcard.NewBuySimCardActivity"
        android:label="@string/title_activity_new_buy_sim_card">
        <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:host="imnumbers.com"
                android:pathPrefix="/buynumber/"
                android:scheme="numbers"/>
        </intent-filter>
    </activity>

【问题讨论】:

    标签: android android-intent textview


    【解决方案1】:

    我终于设法修复它。问题在于尾部斜杠\。删除它们解决了这个问题。

    <activity
        android:name=".simcard.NewBuySimCardActivity"
        android:label="@string/title_activity_new_buy_sim_card">
        <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:host="imnumbers.com"
                android:pathPrefix="/buynumber"
                android:scheme="numbers"/>
        </intent-filter>
    </activity>
    

    【讨论】:

      【解决方案2】:

      你说你在这里尝试了答案。 Android TextView with Clickable Links: how to capture clicks?

      你和setMovementMethod一起试过答案了吗? tv.setMovementMethod(LinkMovementMethod.getInstance());

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-22
      • 2018-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-29
      • 1970-01-01
      相关资源
      最近更新 更多