我有一个应用程序(应用程序A),其内容为:com.example.sumbission5finalproject。当我使用内容提供商访问其他应用程序时。我无法访问getcontentresolver()。query。 这是我的班级数据库合同databasecontract 这是我在应用B manifest
中的清单当我更改com.example.sumbission5finalproject清单的权限时。然后发生错误 error
如何解决? 这是我在调用getcontentresolver时的方法
public ArrayList<FavoriteModel> getFavoriteMovie(Context context, FavoriteModel movieFavoriteModel1) {
ArrayList<FavoriteModel> arrayList = new ArrayList<>();
cursor = context.getContentResolver().query(CONTENT_URI, new String[]{movieFavoriteModel1.getKategori(), movieFavoriteModel1.getBahasa()}, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
FavoriteModel movieFavoriteModel;
if (cursor.getCount() > 0) {
do {
movieFavoriteModel = new FavoriteModel();
movieFavoriteModel.setId(cursor.getInt(cursor.getColumnIndexOrThrow(_ID)));
movieFavoriteModel.setIdmovie(cursor.getString(cursor.getColumnIndexOrThrow(IDMOVIE)));
movieFavoriteModel.setKategori(cursor.getString(cursor.getColumnIndexOrThrow(KATEGORI)));
movieFavoriteModel.setJudul(cursor.getString(cursor.getColumnIndexOrThrow(JUDUL)));
movieFavoriteModel.setOverview(cursor.getString(cursor.getColumnIndexOrThrow(OVERVIEW)));
movieFavoriteModel.setGambarposter(cursor.getString(cursor.getColumnIndexOrThrow(GAMBARPOSTER)));
movieFavoriteModel.setBahasa(cursor.getString(cursor.getColumnIndexOrThrow(BAHASA)));
movieFavoriteModel.setTglrilis(cursor.getString(cursor.getColumnIndexOrThrow(TGLRILIS)));
movieFavoriteModel.setGambarcontent(cursor.getString(cursor.getColumnIndexOrThrow(GAMBARCONTENT)));
arrayList.add(movieFavoriteModel);
cursor.moveToNext();
} while (!cursor.isAfterLast());
}
cursor.close();
}
return arrayList;
}
这是我在Apps B中的内容提供商
@Nullable
@Override
public Cursor query(@NonNull Uri uri, @Nullable String[] strings, @Nullable String s, @Nullable String[] strings1, @Nullable String s1) {
FavoriteModel movieFavoriteModel = new FavoriteModel();
Log.v("jajal1",String.valueOf(uri)); // not print uri in here
Log.v("jajal1","masuk");
favoriteHelper.open();
Cursor cursor;
switch (sUriMatcher.match(uri)) {
case FAVORITE:
if (strings != null) {
Log.v("jajal1",strings[0]+strings[1]+"kosong");
movieFavoriteModel.setKategori(strings[0]);
movieFavoriteModel.setBahasa(strings[1]);
}
cursor = favoriteHelper.getFavoriteMovieProvider(movieFavoriteModel);
break;
case GET_FAVORITE_SEARCH:
if (strings != null) {
movieFavoriteModel.setKategori(strings[0]);
movieFavoriteModel.setBahasa(strings[1]);
movieFavoriteModel.setJudul(strings[2]);
}
cursor = favoriteHelper.getFavoriteMovieProviderSearch(movieFavoriteModel);
break;
default:
cursor = null;
break;
}
return cursor;
}