Im trying to do the next:
- Find image from device and add it to programm (done!)
- Store image URI to string and save it to .txt file (done!)
- Extract URI from .txt file (done!)
- Open a dialog window to show the image on click - and there is a problem - i've tryied everything i found on google and stack overflow - both methods does not work - drawable returns no image (drawable = null), and setImageURI crashes the application. Debugger shows something like that:
content://com.android.providers.media.documents/document/image%3A31
code:
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.pop_up_add_item, null);
final Button btn=view.findViewById(R.id.test);
imgg=view.findViewById(R.id.img);
String str_tooltip=getArguments().getString("Entity");
String main_str=getArguments().getString("Original");
String str_adress=getArguments().getString("Uri");
Uri uri = Uri.parse(str_adress);
//imgg.setI(uri);
if (str_adress!=null & str_adress.length()>0) {
final Uri uri1 = Uri.parse(str_adress);
//final String path = uri.getPath();
//File drawableFile = new File(getApplicationContext().getFilesDir().getAbsolutePath()+"/into11.png");
//final Drawable drawable = Drawable.createFromPath(path);
imgg.setImageURI(uri);
}
Is there any solution on this? Probably common problem?
UPDATE
After tried all the available options eventually (thanks to sir @Dilshad) i've found that the trouble is caused by java.lang.SecurityException: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord{1a24ed9 11931:com.example.myapplication/u0a121} (pid=11931, uid=10121) requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
--> Permission issue.
So, trying to solve it i added:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:ignore="ScopedStorage"/>
in AndroidManifest
and
int result = ContextCompat.checkSelfPermission(takeThis, android.Manifest.permission.READ_EXTERNAL_STORAGE);
in the place in the code where the access begins.
But till the moment problem is not solved.