Aug 8 | 8:55 AM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Aug 8 | 9:00 AM |
Ed T. | has entered the room |
Ed T. |
Good morning sir
|
Mark M. |
hello, Ed!
|
Mark M. |
how can I help you today?
|
Ed T. |
I've been struggling with a defect that I need to fix
|
Mark M. |
reclassify it as a feature!
|
Ed T. |
what makes it a pita.... is I can only use KitKat to fix this issue :(
|
Ed T. |
lol
|
Mark M. |
you can only use KitKat to *fix* the issue, or to reproduce it?
|
Ed T. |
I've got a kiosk type of product... it is actually a Pipo
|
Mark M. |
as in https://www.pipo-store.com/ ?
|
Ed T. |
yes sir
|
Ed T. | |
Ed T. |
a user needs to stick in a jump drive and get an image
|
Ed T. |
auto mount works... and the image is there
|
Ed T. |
Uri path to image = content://com.android.externalstorage.documents...
|
Ed T. |
I get something like this back as a uri
|
Aug 8 | 9:05 AM |
Ed T. |
I'm not able to create a file with that and do anything
|
Mark M. |
what are you trying to do with the image?
|
Ed T. |
the part that is confusing and why I'm glad I came to see you today. :-)
|
Mark M. |
put it in an ImageView? copy it to the device? something else?
|
Ed T. |
I need to put it in an imageView, then save it to a folder on the device after validation
|
Mark M. |
you can load it into the ImageView easily enough using your favorite image-loading library: Glide, Picasso, etc.
|
Mark M. |
they know how to handle that sort of Uri
|
Ed T. |
all of the 'standard ways of doing this... call API calls I can't use
|
Mark M. |
those libraries have versions that work on API Level 19, even if they are not the latest versions
|
Ed T. |
View paste
|
Mark M. |
OK, that's how you are getting the Uri
|
Ed T. |
the flag might be over kill
|
Mark M. |
yes, that's unnecessary
|
Mark M. |
you use that when you are the one giving a Uri to somebody else
|
Mark M. |
so, again, for displaying the image, Glide and Picasso can handle that Uri
|
Mark M. |
for when you eventually want to make a copy, use ContentResolver and openInputStream() to get an InputStream on the content identified by the Uri, then copy the bytes from the InputStream to some FileOutputStream on your desired file
|
Ed T. |
I'm guessing do that in an AsyncTask correct?
|
Mark M. |
a background thread of some form, yes
|
Ed T. |
I went dumpster diving in your large GitHub repot. :-)
|
Ed T. |
lot there
|
Mark M. |
I write a lot :-)
|
Aug 8 | 9:10 AM |
Ed T. |
Your parents should be proud
|
Ed T. |
you've definitely got the golden star on great Android examples. :-)
|
Mark M. |
I try to be useful
|
Ed T. |
thanks for doing that
|
Mark M. |
you're welcome!
|
Ed T. |
so basically... The Uri resource I have to use to copy only to an area where I have full rights to the file?
|
Ed T. |
anything else I try to do and I've tried lots of things...
|
Mark M. |
think of the Uri as a URL to a Web site, and think of the "copy" as "download"
|
Ed T. |
I end up with a file that not only doesn't do anything.... file.exists() always returns FALSE
|
Mark M. |
that Uri is not a file
|
Ed T. |
the iOS examples where a little cleaner... and made more sense to me
|
Mark M. |
just as a URL is not a file
|
Ed T. |
because they give uri resources and everything is locked down... and The Uri has a short 'time to live' with no guarantees
|
Ed T. |
the weird part.. maybe just because Android supports remote media
|
Mark M. |
the Uri is useful for the life of your activity that gets onActivityResult()
|
Mark M. |
(assuming the user doesn't yank out the thumb drive in the middle of your using it)
|
Ed T. |
so that is the other rub... I'm not in an Activity
|
Mark M. |
that ACTION_OPEN_DOCUMENT bit is in an activity
|
Ed T. |
I'm actually in a DialogFragment
|
Mark M. |
from the standpoint of the Uri, that's part of the activity
|
Ed T. |
but I pass a reference to a context
|
Aug 8 | 9:15 AM |
Mark M. |
your DialogFragment already has a reference to the activity that is displaying it
|
Ed T. |
it's actually being displayed by... class BorderEditLayout extends RelativeLayout
|
Mark M. |
sorry, I'm not certain what "it's" refers to in that sentence
|
Ed T. |
it is rather ugly but sadly... the folks who wrote this didn't read your book first. :-)
|
Ed T. |
the dialog class
|
Mark M. |
that should not change the fact that the DialogFragment knows the activity that hosts it, and it should not affect your use of the Uri
|
Ed T. |
and it has a constructor to a context... where it gets created on the MainActivity
|
Mark M. |
if you wanted to pass the Uri to a service, then there's an additional step or two
|
Mark M. |
FWIW, https://gitlab.com/commonsguy/cw-jetpack-java/t... and https://gitlab.com/commonsguy/cw-jetpack-java/t... are my two most recent examples showing ACTION_OPEN_DOCUMENT, though they are reading in text files rather than copying image files
|
Mark M. |
both are profiles in *Elements of Android Jetpack*
|
Mark M. |
er, "profiled"
|
Ed T. |
thanks Mark!
|
Ed T. |
at least I know the direction and path you've put me on is not a dead end
|
Ed T. |
googling for a kit Kat solution... is 'painful'
|
Ed T. |
happy Thursday!
|
Mark M. |
thanks, you too!
|
Aug 8 | 9:25 AM |
Ed T. | has left the room |
Aug 8 | 10:00 AM |
Mark M. | turned off guest access |