从android Studio的其他应用程序获取Url



从其他来源/应用程序获取Url。就像当你点击YouTube上的分享按钮时,你会看到一堆应用程序。

我如何在我的应用程序中实现这个功能。

——示例用x app打开url

我已经在网上搜索过了,但是没有找到。

试试这个,在你的manifest中,把它放在应用启动时打开的第一个活动中,比如SplashActivity

<intent-filter android:label="testing">
<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="www.youtube.com" />
</intent-filter>

并检索数据从您的活动的onCreateView()的下面把下面的

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.splash_activity)

//this is what you need here
val action: String? = intent?.action
val data: Uri? = intent?.data
}

查看更多说明。检查深度链接

为传入链接添加意图过滤器

<intent-filter android:label="@string/filter_view_http_gizmos">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
<data android:scheme="http"
android:host="www.example.com"
android:pathPrefix="/gizmos" />
<!-- note that the leading "/" is required for pathPrefix-->
</intent-filter>

从传入意图读取数据

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
val action: String? = intent?.action
val data: Uri? = intent?.data
}

只要在你的应用中改变你想要接受的意图过滤器中的链接。

最新更新