Office Hours — Today, May 17

Tuesday, May 15

May 17
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Suleyman O.
has entered the room
Suleyman O.
Hi Mark! How are you doing today?
Mark M.
OK, and you?
Suleyman O.
OK as well :)
Mark M.
how can I help you today?
Suleyman O.
I have a question about FileProvider
I have a small app that takes pictures via an intent and saves the file URIs in a database. The storage is accessed using getExternalStoragePublicDirectory with picture directory and I am using the FileProvider.getUriForFile with name=“my_images” and path=“.” . Is it safe to do this? Because in your book you state that <external-path> can be used to serve files from getExternalStoragePublicDirectory, but some posts on StackOverflow state that FileProvider has no support for it.
Mark M.
<external-path> has worked since the beginning of FileProvider, for serving from the root of external storage
so, that should be safe
7:30 PM
Mark M.
assuming that by getExternalStoragePublicDirectory(), you are referring to the method on android.os.Environment
Suleyman O.
yes, exactly
perfect, thanks, it was bugging me
Since there is no one yet...I have the last question
Mark M.
go right ahead!
Suleyman O.
I have a BottomNavigationView with fragments, one of the fragments contains photos, and before entering it I need to ask for external storage permission (because I am looking up the image directory and comparing it to my database). But I think because I am doing it just before leaving the activity, it only works with commitAllowingStateLoss
My Activity acts primarily as a container and a communication system between fragments
7:35 PM
Suleyman O.
is it a bad approach? Or should I use my permission elsewhere and just use commit()
Mark M.
I guess I do not understand where you are leaving the activity
it sounds like you are switching between fragments in one activity
so, when the user taps on the navigation item to switch to the fragment that needs the permission, if you do not have the permission, hold off populating the fragment until the user grants permission
Suleyman O.
yeah, exactly...my bad, I am not leaving the activity, I am just switching fragments
Mark M.
if you wait to request the permission until navigation has completed, I would not expect you to need commitAllowingStateLoss()
that being said, if you are sure that there is no relevant state to lose, and you want to use commitAllowingStateLoss(), that is your call to make
personally, I view commitAllowingStateLoss() as a code smell, and would recommend trying to avoid it, using it only as a last resort
Suleyman O.
I understand I think the problem is that I check if the permission is granted and if it is, I launch my database verifying code and commit the fragment at the same time
Mark M.
what fragment are you committing?
7:40 PM
Suleyman O.
The one that contains the photos, basically I check if the permission is granted, and if it is, I compare photos in the database with the photos in the directory and switch to my fragment
both actions happen at the same time, I believe that what's causing it
Mark M.
I do not completely understand your app and its flow, but I would consider doing the fragment switch first, then in the *new* fragment do the permission check, followed by the database I/O
Suleyman O.
I just read it and understood how confusing it was :D you are right, that way I don't have to worry about it. Maybe I'll request the permission before entering and upon entering run the database check
Thanks a lot Mark :)
Sorry if it was confusing, it's 1 in the morning, the day was long :)
Mark M.
FWIW, Saturday's office hours are friendlier for your time zone
Suleyman O.
That is true :)
7:45 PM
Suleyman O.
Have a great evening Mark :)
Mark M.
you too!
Suleyman O.
See you later!
8:00 PM
Suleyman O.
has left the room
8:25 PM
Mark M.
turned off guest access

Tuesday, May 15

 

Office Hours

People in this transcript

  • Mark Murphy
  • Suleyman Orazgulyyev