Używam dostawcy treści KITKAT w mojej aplikacji. Po uzyskaniu informacji o wybranym zdjęciu przechowuję go w bazie danych, aby móc z niego korzystać później. Problem polega na tym, że po ponownym uruchomieniu telefonu otrzymałem wyjątek uprawniający do korzystania z przechowywanego pliku URI.android takePersistableUriPermission nie kompiluje się
Po wyszukiwaniu próbowałem użyć takePersistableUriPermission() Ale z jakiegoś powodu nie kompiluje się (korzystam z androidstudio).
Błąd: musi to być jeden lub więcej elementów IntentFLAG_GRANT_READ_URI_PERMISSION lub Intent.FLAG_GRANT_WRITE_URI_PERMISSION. Występuje na drugim argumencie metodzie takePersistableUriPermission (flaga)
Oto kod:
Intent intent;
if (Build.VERSION.SDK_INT < 19){
intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, ANDROID_LESS_19);
} else {
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(intent, ANDROID_MORE_19);
}`
case ANDROID_MORE_19:
if(resultCode == RESULT_OK){
Uri selectedImage = data.getData();
mImage = selectedImage.toString();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
// this part means to keep permanent permissions, so no exception after rebooting the device
final int takeFlags = data.getFlags()
& (Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
getContentResolver().takePersistableUriPermission(selectedImage, takeFlags);
grantUriPermission("com.main.bonappetit", selectedImage, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
Cursor cursor = getContentResolver().query(
selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
Ktoś wie co się dzieje tutaj?
Używaj bitowego lub zamiast AND aby połączyć dodatkowe flagi. – corsair992
Dziękuję za odpowiedź. Próbowałem go zastąpić, ale nadal mam ten sam błąd. – totomac
W końcu udało mi się go skompilować za pomocą eclipse zamiast androidstudio – totomac