gpt4 book ai didi

android - 直播 channel - 查询返回安全异常

转载 作者:行者123 更新时间:2023-11-30 02:01:31 30 4
gpt4 key购买 nike

除了无法解释的 Sample TV Input 应用 (https://github.com/googlesamples/androidtv-sample-inputs/),没有很多关于如何在 Live Channels 应用中创建直播 channel 的文档。

我使用 ContentResolver 插入 channel 信息,但如果我尝试使用更新方法更新此信息,我会收到错误消息:

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" />

最佳答案

该解决方案需要一些不同的方法来使用内容解析器查询项目。

查询 android.media.tv 其中 channel = 1 会产生安全异常,但有一个基于示例代码的解决方法。

您可以更改源查询以仅包含您想要的 channel 。例如,您可以使用 URI content://android.media.tv/channel/150

更新或删除

关于android - 直播 channel - 查询返回安全异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31377712/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com