【发布时间】:2017-01-21 09:40:20
【问题描述】:
我想获得分享意图的链接。当我通过 chrome 收到链接时,其格式正确,但有时其他应用程序也会添加文本。
例子:
Chrome:“www.recode.net/2016/7/21/12243560/google-machine-learning-comics-play”
Twitter:“大家看看这个链接,太酷了https://www.recode.net/2016/7/21/12243560/google-machine-learning-comics-play”
因此,对于 twitter,我想摆脱所有上下文,只保留链接,即 www.recode.net/2016/7/21/12243560/google-machine-learning-comics-play
注意:链接可以是任何格式 https://..(或)www。 ..(或)recode.net/...(开头没有 www)。
任何正则表达式来解决这个问题?
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shareintent);
// Get intent, action and MIME type
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null)
{
if ("text/plain".equals(type))
{
// Handle text being sent
handleSendText(intent);
}
}
}
void handleSendText(Intent intent)
{
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null)
{
// Update UI to reflect text being shared
TextView tvShare = (TextView) findViewById(R.id.tvShare);
tvShare.setText(sharedText);
}
}
【问题讨论】:
-
您可以搜索至少包含一个“.”的字符串。也许是 4 个字符? (没有空格)
-
这段代码的相关性如何/到目前为止您尝试了什么?