【问题标题】:Cannot link to new Activity from Linkify pattern无法从 Linkify 模式链接到新活动
【发布时间】:2017-08-22 13:46:31
【问题描述】:

我正在尝试获取某种文本模式来打开 Intent。文本模式正确链接。单击列表视图中的文本@username 应打开下面指定的活动。相反,它会打开一个对话框,上面写着"Open with... No apps can perform this action.",并且活动不会改变。这里有什么?

链接代码:

// Linkify @mentions
Linkify.TransformFilter filter = (match, url) -> match.group();
Pattern mentionPattern = Pattern.compile("@([A-Za-z0-9_-]+)");
String mentionScheme = "com.test.android.activity.UserProfileActivity://";
Linkify.addLinks(feedItemView.messageText, mentionPattern, mentionScheme, null, filter);

清单:

<activity
    android:name=".activity.UserProfileActivity"
    android:configChanges="keyboardHidden|orientation|screenSize"
    android:label="@string/app_name"
    android:launchMode="singleTask"
    android:parentActivityName=".activity.UserProfileActivity"
    android:screenOrientation="portrait"
    tools:ignore="UnusedAttribute">
    <intent-filter>
        <category android:name="android.intent.category.DEFAULT" />
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="com.test.android.activity.UserProfileActivity" />
    </intent-filter>
</activity>

我以此为指导:http://cogitas.net/blog/2011/01/05/linkify-your-android-textview/

【问题讨论】:

    标签: java android linkify


    【解决方案1】:

    回答这个问题可能为时已晚,但对于其他人来说,这就是我解决问题的方法。 将此实现到您的 textView

    String json_string = "{"mention_id":"1","mention_username":"mj"}";
      Pattern username_pattern = Pattern.compile("mj");
      Linkify.addLinks(yourTextView,username_pattern, "input.your.scheme://"+ json_string));
    yourTextView.setLinkTextColor(Color.BLUE); // add a color to your mentioned
    

    到你的 AndroidManifest.xml

     <activity android:name="The activity that you want to open"
            android:theme="@style/Theme.Transparent"> // add your theme here
            <intent-filter android:label="@string/app_name">
                <category android:name="android.intent.category.DEFAULT" />
                <action android:name="android.intent.action.VIEW" />
                <data android:scheme="input.your.scheme" />// for getting the scheme of your intent from linkify
            </intent-filter>
        </activity>
    

    并从意图获取数据到您的活动。将此添加到您要打开的活动中的 onCreate

    //you can now parse your data here
    Uri data = getIntent().getData();
        if (data!=null){
            if (data.toString().contains("input.your.scheme://")){
                String[] strip_id = data.toString().split("//");
                try {
                    JSONObject jsonObject_mention = new JSONObject(strip_id[1]);
                    getSpecificUserProfile(jsonObject_mention.optString("mention_id"));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-15
      • 2016-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-16
      相关资源
      最近更新 更多