【发布时间】:2014-11-25 19:46:44
【问题描述】:
我们正在尝试连接我们的 AndroidTV 应用以将结果附加到全局搜索中。我遇到了一个问题,我无法通过 api 调用来获取结果,因为系统在主线程上调用了我的内容提供程序。
@Override
public Cursor query(Uri uri, String[] projection, String search, String[] selectionArgs, String searchOrder) {
... Logic here that calls the API using RxJava / Retrofit
return cursor;
}
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/foo"
android:searchSettingsDescription="@string/foo_results"
android:includeInGlobalSearch="true"
android:searchSuggestAuthority="com.foo.search.provider"
android:searchSuggestIntentAction="android.intent.action.VIEW" />
<provider
android:authorities="com.foo.search.provider"
android:name=".search.GlobalSearchProvider"
android:exported="true"/>
当我进行全局搜索时,我可以看到 ContentProvider#query 被调用。如果我尝试在当前线程上进行 api 调用,我会得到 networkonmainthreadexception。
我已尝试通知光标数据已更改,但也没有成功。
getContext().getContentResolver().notifyChange(Uri.parse("content://com.foo.test"), null);
...
cursor.setNotificationUri(getContext().getContentResolver(), Uri.parse("content://com.foo.test"));
我是否可以强制操作系统在单独的线程上调用内容提供程序,或者至少通知搜索光标有新内容?
谢谢
【问题讨论】:
标签: android android-tv