Office Hours — Today, September 20

Saturday, September 10

Sep 20
7:20 PM
Mark M.
has entered the room
Mark M.
turned on guest access
7:40 PM
Kathy
has entered the room
Mark M.
howdy, Kathy!
Kathy
hi
Mark M.
how can I help you today?
Ron B.
has entered the room
Ron B.
Hi Mark!
Mark M.
howdy, Ron!
Kathy: do you have a question?
JamesMoore
has entered the room
Mark M.
gadzooks, it's a veritable army of chatters! :-)
Kathy
I want to write a jpeg to the SD card and wanted to know the best way to do it.
Mark M.
howdy, James!
JamesMoore
Hello
Mark M.
Kathy: that's mostly just standard Java I/O
JamesMoore
So I've been playing around a bit with scala
Kathy
I am also not sure what folder to put the jpeg in. I am going to allow the user to save a wallpaper image.
Mark M.
James: hang on, let me take things one at a time
JamesMoore
sure, no problem
Kathy
Does every phone have the same folder where the photos are put?
Mark M.
Kathy: if your app is only for API Level 8 (Android 2.2) and up, use Environment.getExternalStoragePublicDirectory() to find out where to write your JPEGs
you also will need the WRITE_EXTERNAL_STORAGE permission
7:45 PM
Kathy
What does that tell me, does it tell me the folder also?
Mark M.
and you will want to consider whether or not external storage is presently available (see Environment.getExternalStorageState())
getExternalStoragePublicDirectory() tells you the preferred directory for various data formats
getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) would tell you where to store images
it returns a File object pointing to the directory
there's an extensive sample in the documentation for that method
Ron B.
View paste (8 more lines)
Having trouble with an e-mail app picking up a file I want to send.

I'm using a Content Provider, overriding the openFile method.  It is getting called, but does not seem to find the file referred to in the uri.

The intent is called as follows:
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://com.valmarc.ima/" foo +".jpg"));

Where openFileInput of foo was successful and indicated that there were bytes available to read

The content provider openFile method, which is called, has the following:
URI fileURI = URI.create("file://" +uri.getPath() +".jpg");
		File file = new File( fileURI);
		
also tried:
		File file - new File(uri.toString()); 
...
Sorry, didn't mean to cut in
Mark M.
Kathy: let me take questions from the others, and I can swing back around to you for follow-up
Ron, you were next into the chat
Kathy
I am almost done. I was looking in the samples to try and fine a write to SD samples but I could not seem to find it.
Oh, sorry, I can wait.
Mark M.
when you say "does not seem to find the file", what do you mean?
Ron B.
I get a file not found from gmail, and false on file.exists()
Mark M.
um, there's no exists() on InputStream
Ron B.
On File.
Mark M.
but there's no File from a ContentProvider
getContentResolver().openFile(), which is what Gmail presumably uses, gets an InputStream
Ron B.
I get the file from the URI:
View paste
URI fileURI = URI.create("file://" +uri.getPath() +".jpg");
		File file = new File( fileURI);
		
also tried:
		File file - new File(uri.toString()); 
...
7:50 PM
Mark M.
but if the Uri is content://..., you can't just magically turn that into a File
Ron B.
So what do I do with it?
Mark M.
I can't answer that
since I have no idea what you are trying to do
Ron B.
I want gmail to send the file, I need a content provider to allow gmail to do this?
Mark M.
yes
Ron B.
The content provider needs an openFile method, right?
Mark M.
yes
View paste
@Override
  public ParcelFileDescriptor openFile(Uri uri, String mode)
    throws FileNotFoundException {
    File f=new File(getContext().getFilesDir(), uri.getPath());
    
    if (f.exists()) {
      return(ParcelFileDescriptor.open(f,
                                        ParcelFileDescriptor.MODE_READ_ONLY));
    }

    throw new FileNotFoundException(uri.getPath());   
  }
in this case, the expected Uri would be of the form FileProvider.CONTENT_URI+"geoweb2.html"
IOW, content://com.commonsware.android.cp.files/geoweb2.html
Ron B.
OK, I'll try that. Thanks!
Mark M.
OK
James: your turn
JamesMoore
Playing with scala. Is there a way to use a different ClassLoader for an app?
Dev time only
Mark M.
not for the whole app
short of modifying firmware
JamesMoore
Looked like you could replace the class loader using the Instrumentation class
Mark M.
that's possible, haven't looked at that
JamesMoore
OK - is there something like Instrumentation for sesrvices?
Mark M.
I'm used to thinking solely for production
JamesMoore
Sure, makes sense
Mark M.
AFAIK, Instrumentation works for services
7:55 PM
Mark M.
after all, there's a ServiceTestCase class, IIRC
JamesMoore
Right, the problem is there's no call to something newService() like there is for newActivity()
Mark M.
oh
JamesMoore
Feels like it should be there
Mark M.
I haven't played with custom instrumentation much
agreed, you would think it would be there for all components
JamesMoore
Fair enough - didn't want to spend time on it if
it was somethign you migh tknow about already
Mark M.
yeah, sorry, outside my areas of experience
JamesMoore
worth a shot, thanks
Mark M.
Kathy: you're up again -- got another question or follow-up on the first?
Kathy
Yes, thanks for your help. Can you tell me where the sample is? I was looking at the android dev samples last night and did not find it.
Mark M.
I was referring to the JavaDocs, for the getExternalStoragePublicDirectory() on Environment
(that link will jump right to the method)
Kathy
Okay, thanks so much.
Mark M.
Ron: do you have another question or a follow-up to your first?
Ron B.
Thanks Mark, I just tried your fix and it worked! I didn't have the right File parameters.
Mark M.
oh, whew
8:00 PM
Mark M.
I got worried when I realized that I misunderstood where you were trying to use the File object
I thought you were trying to *consume* the content provider with it, not support openFile()
JamesMoore
(nothing more from me, just hanging out now)
Mark M.
well, it's a free-for-all now, at least unless somebody else new shows up
Ron B.
No, it was in the right spot, just wrong code :-)
Mark M.
anyone with a question, chime in
Ron B.
All set here
JamesMoore
any way to get the nice text selection system in 2.3 in versions before that? handles on the selection that can be dragged, that sort of thing
don't need copy/paste, just select
Mark M.
not that I am aware of
I suppose you could poke around the source for EditText and see how they do it
JamesMoore
or external libraries that do something useful?
Kathy
I wish I could think up a question right now but I was just looking around your docs and thought I would just check and see if there was an office chat and voila, so I have no prepared questions right now.n
JamesMoore
Yeah, I was hoping to avoid that :-)
Mark M.
however, it might run into problems on various devices
I haven't seen a library for extending EditText with selection stuff, but I haven't exactly been looking
the world needs a sexy go-to Android component library site
JamesMoore
that would be handy
8:05 PM
JamesMoore
thanks, ltr
Mark M.
see ya!
8:15 PM
Mark M.
again, if anyone has a question, feel free to ask
8:30 PM
Mark M.
OK, that's a wrap for today's chat
another one Thursday. same time
have a pleasant day, all!
Kathy
has left the room
Ron B.
has left the room
JamesMoore
has left the room
Mark M.
turned off guest access

Saturday, September 10

 

Office Hours

People in this transcript

  • JamesMoore
  • Kathy
  • Mark Murphy
  • Ron Bruckman