sjo*_*jor 4 java media youtube android android-intent
我已经开发了自己的媒体播放器,我希望当我想观看Youtube上的视频时,它应该从我的应用程序中打开.至少,视图上应该有一个媒体应用列表,我应该可以从列表中选择我的应用.我对intent-filters了解不多.我如何在清单文件中提供此信息?我正在努力为本地文件进行训练,但我还没能做到.我真的需要你的帮助 :/
H9k*_*oid 11
如果您查看官方YouTube应用程序使用的intent过滤器,您将看到:
<activity android:name="Player">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="youtube.com" android:pathPrefix="/watch" />
<data android:scheme="https" android:host="youtube.com" android:pathPrefix="/watch" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="*.youtube.com" android:pathPrefix="/watch" />
<data android:scheme="https" android:host="*.youtube.com" android:pathPrefix="/watch" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="www.youtube.com" android:pathPrefix="/v/" />
<data android:scheme="https" android:host="www.youtube.com" android:pathPrefix="/v/" />
<data android:scheme="http" android:host="www.youtube.com" android:pathPrefix="/e/" />
<data android:scheme="https" android:host="www.youtube.com" android:pathPrefix="/e/" />
<data android:scheme="http" android:host="www.youtube.com" android:pathPrefix="/embed/" />
<data android:scheme="https" android:host="www.youtube.com" android:pathPrefix="/embed/" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="vnd.youtube" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
要获取视频ID,您可以解析从中获得的字符串:
Uri uri = this.getIntent().getData();
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,youtu.be没有过滤器,但可以添加:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="youtu.be" />
<data android:scheme="https" android:host="youtu.be" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)