在我的应用程序 list 中,我编写了以下代码来打开一些链接,其中我的应用程序添加了 Intent 过滤器:
<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:scheme="https" android:host="example.com" />
</intent-filter>
我尝试通过电子邮件向自己发送一个链接;例如:http://www.example.com/1234
。单击链接我打开应用程序.. 太棒了。现在,是否可以将链接的 1234 部分放入 TextView 中?像这样的东西:
mTextView.setText(textFromLink);
谢谢
最佳答案
您已经可以访问应用内的 URL 了吗?如果没有,您可以获取它,例如在您的 onCreate
方法中使用
Uri link = getIntent().getData();
返回一个 Uri 对象: http://developer.android.com/reference/android/net/Uri.html
该对象有多种方法来获取 URL 的特定部分。在你的情况下,它可能是
字符串内容 = link.getLastPathSegment()
:
http://developer.android.com/reference/android/net/Uri.html#getLastPathSegment()
这将返回一个您可以在 TextView 中设置的字符串:
mTextView.setText(content);
关于java - 点击后在Android应用程序中传递部分链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26361702/