Doc*_*aux 4 youtube android android-intent android-11
我目前很难在浏览器或 YouTube 应用程序中打开 YouTube 链接。我知道Android 11 中新的包可见性并以这种方式实现。
MyClass.java$myMethod
String ytLink = "https://www.youtube.com/watch?v=Hp_Eg8NMfT0"
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(ytLink));
if (intent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml
<manifest>
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
</queries>
</manifest>
Run Code Online (Sandbox Code Playgroud)
然而,intent.resolveActivity返回null...我尝试过的每个其他链接都返回一个ComponentName,以便Intent可以启动...您有任何线索吗?
提前致谢 ;)
另一种选择是将主机添加到清单中的查询列表中:
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" android:host="youtube.com" />
</intent>
</queries>
Run Code Online (Sandbox Code Playgroud)
似乎仅使用方案的简单方法失败了,因为 Youtube 应用程序不仅过滤请求的方案,而且(出于明显的原因)还过滤特定主机。
顺便说一句:当我测试时,“youtube.com”和“youtu.be”在这两种链接上效果相同。为了安全起见,我仍然将两者都放入了我的应用程序中。
| 归档时间: |
|
| 查看次数: |
4594 次 |
| 最近记录: |