[英]How to access the entire TV Provider database by TV Input Manager?
由設備制造商(簽名應用程序)或安裝在系統分區中的其他應用程序提供和簽名的 TV Input 將有權訪問整個 TV Provider 數據庫。 此訪問權限可用於構建應用程序以瀏覽和搜索所有可用的電視頻道和節目。
假設我以設備制造商的身份簽名或在系統分區中安裝了應用程序,我如何訪問 TvProvider 及其頻道信息?
編輯:
val tifSupport: Boolean = packageManager.hasSystemFeature(PackageManager.FEATURE_LIVE_TV)
Log.d("XXX", "TIF Support ? $tifSupport")
這條線說的是真的。 然后我運行這些行:
val tvInputManager = applicationContext.getSystemService(TV_INPUT_SERVICE) as TvInputManager?
Log.d("XXX", "TvInputManager $tvInputManager")
val il = tvInputManager?.tvInputList
Log.d("XXX", "TvInputList size --> ${il?.size}")
tvInputManager?.tvInputList?.forEach { info ->
Log.d("XXX", "TvInputListInfo ${info.id} ${info.serviceInfo} # ${info.extras.size()}")
}
第一個日志打印
TvInputManager android.media.tv.TvInputManager@95728c2
所以 tvInputManager 看起來有效。 第二個顯示 0 作為 TvInputList 大小,因此根本不打印第三個日志(在 forEach() 中)。
您必須從 Android 的背景開始。 文檔中的提供者是指ContentProvider
,它將在 Android 內的進程之間共享信息。 現在開始:
然后您將能夠使用ContentProvider
來獲取您需要的所有類型的信息。 要查看對 TVContent Provider 的完整支持,您可以參考此文件(確保它與您的 Android 操作系統版本一致)和其他 AOSP 信息。 例如。
/**
* Returns the current list of channels your app provides.
*
* @param resolver Application's ContentResolver.
* @return List of channels.
*/
public static List<Channel> getChannels(ContentResolver resolver) {
List<Channel> channels = new ArrayList<>();
// TvProvider returns programs in chronological order by default.
Cursor cursor = null;
try {
cursor = resolver.query(Channels.CONTENT_URI, Channel.PROJECTION, null, null, null);
if (cursor == null || cursor.getCount() == 0) {
return channels;
}
while (cursor.moveToNext()) {
channels.add(Channel.fromCursor(cursor));
}
} catch (Exception e) {
Log.w(TAG, "Unable to get channels", e);
} finally {
if (cursor != null) {
cursor.close();
}
}
return channels;
}
另一個前任。
TvInputManager tv = (TvInputManager)getApplicationContext().getSystemService(Context.TV_INPUT_SERVICE);
List<TvInputInfo> list = tv.getTvInputList();
String[] projection = {
TvContract.Channels._ID,
TvContract.Channels.COLUMN_DISPLAY_NUMBER
};
ContentResolver cr = getContentResolver();
Iterator<TvInputInfo> it = list.iterator();
while(it.hasNext()) {
TvInputInfo aux = it.next();
Uri uri = TvContract.buildChannelsUriForInput(aux.getId());
Log.d("TAG", uri.toString());
Log.d("TAG", aux.toString());
Cursor cur = cr.query(uri, projection, null, null ,null);
Log.d("TAG", cur.toString());
if(cur.moveToFirst()) {
Log.d("TAG", "not empty cursors");
}
}
更新:
您應該擁有的基本權限(另請參閱官方文檔):
<uses-permission android:name="com.android.providers.tv.permission.READ_EPG_DATA" />
<uses-permission android:name="com.android.providers.tv.permission.WRITE_EPG_DATA" />
<uses-permission android:name="com.android.providers.tv.permission.ACCESS_ALL_EPG_DATA"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.