除了无法解释的样本电视输入应用程序(https://github.com/googlesamples/androidtv-sample-inputs/)之外,还没有很多关于如何在直播频道应用中创建直播频道的文档。
我使用ContentResolver插入频道信息,但如果我尝试使用更新方法更新此信息,则会收到错误消息:
07-13 03:25:55.695 29194-29194/com.felkertech.n.cumulustv E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.felkertech.n.cumulustv, PID: 29194
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.felkertech.n.cumulustv/com.felkertech.n.cumulustv.SampleSetup}: java.lang.SecurityException: Selection not allowed for content://android.media.tv/channel
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.SecurityException: Selection not allowed for content://android.media.tv/channel
at android.os.Parcel.readException(Parcel.java:1540)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
at android.content.ContentProviderProxy.update(ContentProviderNative.java:567)
at android.content.ContentResolver.update(ContentResolver.java:1333)
at com.felkertech.n.cumulustv.SampleSetup.onCreate(SampleSetup.java:81)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
这是查询的代码,即使在几次迭代的反复试验之后似乎也不起作用:
values.put(TvContract.Channels.COLUMN_INPUT_ID, info);
values.put(TvContract.Channels.COLUMN_DISPLAY_NUMBER, channel.number);
values.put(TvContract.Channels.COLUMN_DISPLAY_NAME, channel.name);
values.put(TvContract.Channels.COLUMN_ORIGINAL_NETWORK_ID, 0);
values.put(TvContract.Channels.COLUMN_TRANSPORT_STREAM_ID, 0);
values.put(TvContract.Channels.COLUMN_SERVICE_ID, 1);
values.put(TvContract.Channels.COLUMN_SERVICE_TYPE, TvContract.Channels.SERVICE_TYPE_AUDIO_VIDEO);
values.put(TvContract.Channels.COLUMN_VIDEO_FORMAT, TvContract.Channels.VIDEO_FORMAT_1080P);
values.put(TvContract.Channels.COLUMN_TYPE, TvContract.Channels.TYPE_OTHER);
values.put(TvContract.Channels.COLUMN_VERSION_NUMBER, 2); //TODO So I need to reset
String[] projection = {TvContract.Channels.COLUMN_INPUT_ID, TvContract.Channels.COLUMN_SERVICE_ID};
Cursor cursor = null;
try {
cursor = getContentResolver().query(TvContract.Channels.CONTENT_URI, projection, null, null, null);
if (cursor != null || cursor.getCount() > 1) {
cursor.moveToNext();
getContentResolver().update(TvContract.Channels.CONTENT_URI, values, "'"+TvContract.Channels.COLUMN_SERVICE_ID + "' = '1'", null);
} else {
Log.d(TAG, "Insert new");
}
getContentResolver().insert(TvContract.Channels.CONTENT_URI, values);
} finally {
if (cursor != null) {
cursor.close();
}
}
Uri uri = getContentResolver().insert(TvContract.Channels.CONTENT_URI, values);
错误似乎来自不正确的权限,但我认为它们已经启用(我可以插入正常):
<!-- Required to play internet-based streaming contents. -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Required to register a SyncStatusObserver. -->
<uses-permission android:name="android.permission.READ_SYNC_STATS"/>
<!-- Required to enable our SyncAdapter after it's created. -->
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
<!-- Required because we're manually creating a new account. -->
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
<!-- Required to update or read existing channel and program information in TvProvider. -->
<uses-permission android:name="com.android.providers.tv.permission.READ_EPG_DATA" />
<!-- Required to update channel and program information in TvProvider. -->
<uses-permission android:name="com.android.providers.tv.permission.WRITE_EPG_DATA" />
答案 0 :(得分:1)
该解决方案需要使用内容解析器查询项目的一些不同方法。
查询android.media.tv
,其中channel
= 1会产生安全异常,但根据示例代码有一种解决方法。
您可以将原始查询更改为仅包含所需的频道。例如,您可以使用URI content://android.media.tv/channel/150