【问题标题】:Live Channels - Query Returns Security Exception直播频道 - 查询返回安全异常
【发布时间】:2015-07-13 07:34:37
【问题描述】:

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

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

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 android-contentresolver android-tv


    【解决方案1】:

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

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

    您可以将来源查询更改为仅包含您想要的频道。例如,您可以使用 URI content://android.media.tv/channel/150 进行更新或删除

    【讨论】:

      猜你喜欢
      • 2016-08-05
      • 2020-03-31
      • 2015-03-05
      • 2019-08-22
      • 1970-01-01
      • 2020-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多