我有以下可搜索的XML声明:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:label="@string/app_name"
android:voiceSearchMode="showVoiceSearchButton"
android:includeInGlobalSearch="true"
android:searchMode="queryRewriteFromText"
android:searchSuggestAuthority="com.mypackage.MyRecentSuggestionsProvider"
android:searchSuggestSelection=" ?"
android:hint="@string/search_hint">
</searchable>
现在是ContentProvider本身:
package com.mypackage.contentProviders
import android.content.SearchRecentSuggestionsProvider
import com.mypackage.BuildConfig
class MySuggestionsProvider : SearchRecentSuggestionsProvider() {
val AUTHORITY = BuildConfig.APPLICATION_ID + ".MySuggestionsProvider"
val MODE = SearchRecentSuggestionsProvider.DATABASE_MODE_QUERIES
init{
setupSuggestions(AUTHORITY, MODE)
}
}
现在的问题是,我在Gradle中有3种风格,所以ContentProvider类中定义权限的行使用应用程序ID使其唯一,这样所有3种风格都可以同时存在于设备上。我记得,两个应用程序不能有重复的权限。
现在讨论我的问题:我不想重写每种风格的searchable.xml,只想为每种风格声明另一个权限。我宁愿这样做:
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:label="@string/app_name"
android:voiceSearchMode="showVoiceSearchButton"
android:includeInGlobalSearch="true"
android:searchMode="queryRewriteFromText"
android:searchSuggestAuthority="{applicationId}.MyRecentSuggestionsProvider"
android:searchSuggestSelection=" ?"
android:hint="@string/search_hint">
</searchable>
我们经常这样做,因为Android清单是一个占位符。是否无论如何,我不必为内容提供程序创建不同的XML声明,而是以某种方式使其每种风格都具有唯一性?