android - 从android中的另一个应用程序共享时如何检索链接?
问题描述
您好,我正在尝试检索从另一个应用程序共享的 url,并对其进行敬酒以及在 WebViewTab 中打开它。但是应用程序的 id 显示在 toast 中。这是我的代码:
val extras = intent.extras
if (extras != null) {
for (key in activity.intent.extras!!.keySet()) {
CopyKey = key
val value: String? = activity.intent.extras!!.getString(CopyKey)
Toast.makeText(applicationContext, value, Toast.LENGTH_LONG).show()
TabInfo.addTab(value.toString())
}
val url = intent.extras!!.getString("query")
if (url.toString().startsWith("http")) {
TabInfo.addTab(url.toString())
intent.removeExtra("query")
}
}
提前致谢
解决方案
这解决了我的问题:
val extras = intent.extras
if (extras != null) {
val externalUrl: Uri? = intent?.data //retrieves the shared text from another app.
val url = intent.extras!!.getString("query")
if (url.toString().startsWith("http")) {
TabInfo.addTab(url.toString())
intent.removeExtra("query")
}
else {
TabInfo.addTab(externalUrl.toString())
}
}
推荐阅读
- java - 如何在Java中获取员工总数?
- python - 查找另一个数据框并过滤值
- c# - 从字符串值中删除引号和转义引号
- c# - C#如何检查按钮在另一个表单中被点击并传递给主表单
- angular - Angular RouteGuard“声明类型既不是'void'也不是'any'的函数必须返回一个值”
- python - 日期时间字符串格式问题
- html - 如何使css在移动设备上显示图像但不在桌面上显示
- javascript - 调试 Minified React 错误 #321 的系统方法
- python-3.x - Python Git 和 Git-Lab 创建项目并推送代码/提交
- python - Pandas 数据帧对特定变量的条件插值