Android:RecentSearchProvider-从字符串资源设置权限?
嗨,我被困在这件事上了 设置这样的RecentSearchProvider 公共类MyRecentSuggestionProvider扩展了SearchRecentSuggestionProvider{Android:RecentSearchProvider-从字符串资源设置权限?,android,history,provider,Android,History,Provider,嗨,我被困在这件事上了 设置这样的RecentSearchProvider 公共类MyRecentSuggestionProvider扩展了SearchRecentSuggestionProvider{ public final static int MODE = DATABASE_MODE_QUERIES; public static String AUTHORITY = "com.xxxxx.authority"; public MyRecentSuggestionProvider() {
public final static int MODE = DATABASE_MODE_QUERIES;
public static String AUTHORITY = "com.xxxxx.authority";
public MyRecentSuggestionProvider() {
super();
setupSuggestions(AUTHORITY, MODE);
}
}
但是,我想从res/strings设置权限,即
setupSuggestions(getContext().getResources().getString(R.string.authority), MODE);
尽管这会得到一个空指针异常
关于如何解决这个问题有什么建议吗?
艾登花了我一段时间,但我找到了一个很好的方法 由于我的应用程序可以针对许多目标构建,使用不同的软件包名称,我做到了这一点
String packagename = getClass().getPackage().getName();
if (packagename.equals("com.company1")){
AUTHORITY = "com.company1.authority";
}else{
AUTHORITY = "com.company2.authority";
}
希望这对别人有帮助