Office Hours — Today, November 14

Monday, November 12

Nov 14
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
7:30 PM
EG H.
has entered the room
EG H.
Hey Mark, don't know if this is the correct place for this but, I was hoping you could help me out with a problem I've been having.
Mark M.
howdy, EG!
feel free to ask -- all I can do is say that I don't know how to help
EG H.
Also, saw you at the BBQ. Two great talks.
Mark M.
thanks!
EG H.
So I have an application that just saves some information in a database.
The end goal is to send the sqlite file in an email to a default email account.
7:35 PM
EG H.
To do this, I can't actually send the sqlite file correct? Because it's private by default?
Mark M.
well, let's back up a step
EG H.
I would need to make a copy of it onto the SD card.
okay
Mark M.
what do you mean by "a default email account"? Some address you're baking into the app?
EG H.
Yes
Mark M.
OK, and you are planning on sending it via ACTION_SENDTO or something?
EG H.
Have no idea yet. Still "new" to programming as a whole, but been working with android mainly.
Mark M.
sorry, ACTION_SENDTO is an Intent action
EG H.
So I guess action_sento looks like a promising piece of code
Oh then yes.
Mark M.
OK
then, the database file, at the time of sending the email, needs to be world-readable
EG H.
I can do that!?
Mark M.
you can do what?
EG H.
The db file can be set to be "world-readable"
Mark M.
yes, if you are on API Level 9 or higher
hmmm... that paste didn't work well...
see setReadable() on File
you would determine the File object via getDatabasePath() on your Activity or other Context
however, *leaving* it world-readable over the long haul is not great from a security standpoint, if there's anything in the file that might be sensitive
bearing in mind that the user, more than you, determines what is sensitive or not
7:40 PM
EG H.
This application will actually never hit the market. Strictly for a personal app for now.
Mark M.
hence, if you make it readable, you will need to undo that sometime
oh, OK
that certainly simplifies things
:-)
EG H.
Yeah
Well, so I originally was going to copy the database and then send it (which I still may have to do)
Mark M.
now, there may still be hiccups trying to send a database on internal storage via email, even if you make it world-readable
in theory it should work
in theory, I'd have more hair
EG H.
Okay
Mark M.
right: copy-and-send is certainly another option
EG H.
So, I'm going to send you a SO link.
Mark M.
might be worth anyway to consider ZIP-and-send, depending database size and compressability
EG H.
My question was closed because it was a duplicate. But my question before was targetting a different answer. Which the members of SO didn't see (or I didn't define it well enough)
Mark M.
that happens
EG H.
Mark M.
um, what is /test4?
oh, nevermind
EG H.
A file that I'm trying to create?
Mark M.
your source path is wrong
use getDatabasePath() to get the correct path
EG H.
is it data/data
Mark M.
yes
7:45 PM
EG H.
Beautiful.
Mark M.
beyond that, there's nothing leaping out at me wrong with the code, though I am not expert on the NIO-based copy process
EG H.
"NIO"?
Mark M.
thing is, it should be failing in that exists() should return false
FileChannel and stuff
EG H.
well when I change the db name or path it does actually fail
Which led me to believe that I was using the correct path.
Mark M.
is your SQLiteDatabase closed at the time you run this code?
EG H.
I don't know (which probably means it is closed...)
I didn't know it could be "opened" is the main point.
Mark M.
well, that's how you work with the database
you cannot rawQuery(), insert(), etc. a closed database
EG H.
I thought it was always private. But I'm not sure if it was made private for the developers or the actual users.
Mark M.
no, no, I mean from within your app
SQLiteDatabase is a class in the Android SDK
you use it to perform operations on the database
EG H.
Yeah, I'm making multiple insert() commands.
So it's open?
Mark M.
at that point, yes.
how are you getting your SQLiteDatabase object?
7:50 PM
EG H.
Sorry (you're gonna want to kill me) but... where?
or
What do you mean "how am i getting it?"
Mark M.
well, objects don't appear out of thin air
hence, your instance of SQLiteDatabase has to be coming from somewhere
EG H.
True.
Objects are created, from classes
Mark M.
it could be getWritableDatabase() on a SQLiteOpenHelper
EG H.
Thanks CS 101. Really coming in handy.
lol
Mark M.
or, it could be from the static openOrCreateDatabase() method on SQLiteDatabase
regardless, somewhere, you are getting a SQLiteDatabase object
and by the time you are calling insert() on it, that SQLiteDatabase object has an open handle to the database file
EG H.
Let me look in my DBHelper class.
Mark M.
I would advise closing that before copying the file
via calling close() on the SQLiteDatabase, or close() on the SQLiteOpenHelper (if you are using one)
EG H.
Oh. Yeah, the database itself is closed at the time I call this code.
Mark M.
OK, that's good
EG H.
Okay, so now I'm on the same page as you.
Mark M.
then, off the cuff, assuming your actual database path is good, it is not immediately obvious to me why the code in your SO question would not work
then again, I haven't tried copying a database to external storage
(BTW, I assume you have the WRITE_EXTERNAL_STORAGE permission, as otherwise you would not have even the 20KB file)
7:55 PM
EG H.
Yes, I do have that permission.
But I'm gonna try your recomendation first.
Mark M.
the 20KB vs 9KB makes it feel like there's some problem in the FileChannel copy logic, so you might double-check that -- again, I rarely use this, so I don't have the mechanics memorized
if you have other questions, feel free to ask -- the chat room is a bit quiet this evening
8:00 PM
EG H.
It will be my pleasure to soak up your intelligence.
View paste
Okay, so I replaced String currentDBPath = "/data/com.test.this/databases/this_db"; with String currentDBPath = getDatabasePath();
But I get a red line underneath "getDabasePath();"
Mark M.
two problems:
EG H.
It needs a parameter of some sort.
Mark M.
1. getDatabasePath() takes the name of the database as a parameter
2. getDatabasePath() returns a File, not a String
8:05 PM
Mark M.
see JavaDocs: http://goo.gl/z3bhU
EG H.
hrm.
Little weird that it's called "getDatabasePATH"
but thats besides the point
Testing new code now.
8:10 PM
EG H.
First things first. The app didn't crash, and the file was created. Now let me drag and drop it over to my computer to see if it's readable by sqlite browser.
8:25 PM
EG H.
Grrr. Still no luck with it.
Think I'll hang it up for today.
Mark M.
I'll add "write a sample of backing up a database to external storage" to my to-do list
though it is a rather long list
EG H.
hahaha
I'll try to get this right by Monday.
Speaking of to do lists.
I actually came out with my first app and it's a to do list.
hahaha
Pretty nifty though.
Mark M.
cool!
8:30 PM
Mark M.
I'm a Remember the Milk guy myself
EG H.
And I've gotten like 100 downloads in 2 weeks and some good reviews.
Mark M.
even better!
EG H.
Check my app out if possible.
"Have To Do"
By "Cereal Bar Apps"
If you type in "Have To Do Cereal" I'm like number 3 on the list.
It's a to do list in your notifications.
I to have a hugggggggge to do list. But there are a couplee of things each day that I "Have To Do"
So it keeps bothering me until I say that I did it.
Not too shabby.
Mark M.
apparently, this includes your homework, based on the screenshot :-)
EG H.
Yes! hahaha.
Please tell me what you think honestly.
I appreciate very harsh (though constructive) criticism
Mark M.
hey, it's a zero-permission app, so you get kudos without my even installing it
EG H.
Down to 1.6 too!
Mark M.
I'll try to take a peek at it sometime, though my schedule is a bit crazed for a while
EG H.
Yeah, crazy simple functionality. Not much substance to it.
Has kept me productive though.
Mark M.
well, that's a wrap for today's chat
EG H.
Anyway. I appreciate the help tonight, and any feedback from you as well.
Thanks again
Mark M.
you are very welcome
next chat is Monday, 10am Eastern
EG H.
You mentioned at the bbq that you're in Philly right?
East coast?
Mark M.
Pennsylvania, though not Philly
8:35 PM
EG H.
Close enough. Hahaha. Yes, I'm from central jersey.
Thanks again, have a good one. See ya on monday
Mark M.
have a pleasant day!
EG H.
has left the room
Mark M.
turned off guest access

Monday, November 12

 

Office Hours

People in this transcript

  • EG HDK
  • Mark Murphy