我正在尝试获取某个文本模式来打开一个Intent。文本模式正确链接。单击列表视图中的文本rng
应打开下面指定的活动。相反,它会打开一个对话框,显示@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);
我以此为指导:http://cogitas.net/blog/2011/01/05/linkify-your-android-textview/
答案 0 :(得分: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();
}
}
}