I currently struggle to have YouTube links to be opened in the browser or the YouTube app. I am aware of the new Package visibility in Android 11 and implemented it this way.
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>
However the intent.resolveActivity
returns null
... Every other link I've tried returns a ComponentName
so the Intent
can be started...
Do you have any clue?
Thanks in advance ;)
Yet another option would be to add the host to the queries list in the manifest:
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" android:host="youtube.com" />
</intent>
</queries>
It seems that the simple approach with just the scheme fails as the Youtube app not only filters for the scheme of the request but (for obvious reasons) also for the specific host.
BTW: When I tested, both "youtube.com" and "youtu.be" worked equally on both kinds of links. I still threw in both in my app to be safe.
You also need to put action
and data
to intent-filter
of Activity in Manifests
Such as
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="https" />
</intent-filter>
You can check the docs here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With