我目前很难在浏览器或 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/