Java 无法从Linkify模式链接到新活动
我试图用某种文本模式来打开一个意图。文本模式链接正确。在列表视图中单击文本Java 无法从Linkify模式链接到新活动,java,android,linkify,Java,Android,Linkify,我试图用某种文本模式来打开一个意图。文本模式链接正确。在列表视图中单击文本@username,将打开下面指定的活动。相反,它会打开一个对话框,上面写着“打开时……没有应用程序可以执行此操作。”,并且活动不会更改。上面是什么 Linkify代码: // Linkify @mentions Linkify.TransformFilter filter = (match, url) -> match.group(); Pattern mentionPattern = Pattern.compil
@username
,将打开下面指定的活动。相反,它会打开一个对话框,上面写着“打开时……没有应用程序可以执行此操作。”,并且活动不会更改。上面是什么
Linkify代码:
// 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>
清单:
// 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>
回答这个问题可能太晚了,但对其他人来说,这就是我解决问题的方法。
在您的文本视图中实现此功能
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>