Android 11/API 30 - 打开 YouTube 链接

标签 android android-intent youtube android-11

我目前很难在浏览器或 YouTube 应用程序中打开 YouTube 链接。
我知道新的 Package visibility in 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); 
}
AndroidManifest.xml
<manifest>
  <queries>
    <intent>
      <action android:name="android.intent.action.VIEW" />
      <data android:scheme="https" />
    </intent>
  </queries> 
</manifest>
然而 intent.resolveActivity返回 null ...我尝试过的所有其他链接都返回 ComponentName所以Intent可以开始...
你有什么线索吗?
提前致谢 ;)

最佳答案

另一种选择是将主机添加到 list 中的查询列表中:

<queries>    
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <data  android:scheme="https" android:host="youtube.com" />
    </intent>
</queries>
似乎仅使用该方案的简单方法失败了,因为 Youtube 应用程序不仅过滤了请求的方案,而且(出于显而易见的原因)也过滤了特定的主机。
顺便说一句:当我测试时,“youtube.com”和“youtu.be”在两种链接上都同样有效。为了安全起见,我仍然在我的应用程序中投入了两者。

关于Android 11/API 30 - 打开 YouTube 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66983878/

相关文章:

android - youtube iframe API 中的广告不适用于 ipad、iphone 和 android

java - 如何使用 GMaps API 将 KML 文件导入 Android 应用程序

android - Cordova 应用程序编译但在运行时崩溃。如何获取错误报告?

java - Android 通知使用 PendingIntent 不是新的

javascript - Youtube API - 一些视频停留在未启动 (-1) 状态

mvvm - Prism 6 和构造函数调用

android - 我们如何使用 Android 在平板电脑中滚动 ListView

android - Flutter:在 Android Studio 中打开 android 模块被禁用

android - 通过 Intent 将图像 url 传递给新 Activity

android - Samsung Galaxy Tab 2 10.1 在按相机 Intent 拍照后终止进程