Nov 14 | 7:25 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Nov 14 | 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!
|
Mark M. |
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.
|
EG H. |
The end goal is to send the sqlite file in an email to a default email account.
|
Nov 14 | 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.
|
EG H. |
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
|
EG H. |
Oh then yes.
|
Mark M. |
OK
|
Mark M. |
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
|
Mark M. | |
Mark M. |
hmmm... that paste didn't work well...
|
Mark M. |
see setReadable() on File
|
Mark M. |
you would determine the File object via getDatabasePath() on your Activity or other Context
|
Mark M. |
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
|
Mark M. |
bearing in mind that the user, more than you, determines what is sensitive or not
|
Nov 14 | 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
|
Mark M. |
oh, OK
|
Mark M. |
that certainly simplifies things
|
Mark M. |
:-)
|
EG H. |
Yeah
|
EG H. |
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
|
Mark M. |
in theory it should work
|
Mark M. |
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. |
If you could take a look. http://stackoverflow.com/questions/1336239…
|
Mark M. |
um, what is /test4?
|
Mark M. |
oh, nevermind
|
EG H. |
A file that I'm trying to create?
|
Mark M. |
your source path is wrong
|
Mark M. |
use getDatabasePath() to get the correct path
|
EG H. |
is it data/data
|
Mark M. |
yes
|
Nov 14 | 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
|
Mark M. |
FileChannel and stuff
|
EG H. |
well when I change the db name or path it does actually fail
|
EG H. |
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...)
|
EG H. |
I didn't know it could be "opened" is the main point.
|
Mark M. |
well, that's how you work with the database
|
Mark M. |
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
|
Mark M. |
SQLiteDatabase is a class in the Android SDK
|
Mark M. |
you use it to perform operations on the database
|
EG H. |
Yeah, I'm making multiple insert() commands.
|
EG H. |
So it's open?
|
Mark M. |
at that point, yes.
|
Mark M. |
how are you getting your SQLiteDatabase object?
|
Nov 14 | 7:50 PM |
EG H. |
Sorry (you're gonna want to kill me) but... where?
|
EG H. |
or
|
EG H. |
What do you mean "how am i getting it?"
|
Mark M. |
well, objects don't appear out of thin air
|
Mark M. |
hence, your instance of SQLiteDatabase has to be coming from somewhere
|
EG H. |
True.
|
EG H. |
Objects are created, from classes
|
Mark M. |
it could be getWritableDatabase() on a SQLiteOpenHelper
|
EG H. |
Thanks CS 101. Really coming in handy.
|
EG H. |
lol
|
Mark M. |
or, it could be from the static openOrCreateDatabase() method on SQLiteDatabase
|
Mark M. |
regardless, somewhere, you are getting a SQLiteDatabase object
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
then again, I haven't tried copying a database to external storage
|
Mark M. |
(BTW, I assume you have the WRITE_EXTERNAL_STORAGE permission, as otherwise you would not have even the 20KB file)
|
Nov 14 | 7:55 PM |
EG H. |
Yes, I do have that permission.
|
EG H. |
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
|
Mark M. |
if you have other questions, feel free to ask -- the chat room is a bit quiet this evening
|
Nov 14 | 8:00 PM |
EG H. |
It will be my pleasure to soak up your intelligence.
|
EG H. |
View paste
|
EG H. |
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
|
Mark M. |
2. getDatabasePath() returns a File, not a String
|
Nov 14 | 8:05 PM |
Mark M. |
see JavaDocs: http://goo.gl/z3bhU
|
EG H. |
hrm.
|
EG H. |
Little weird that it's called "getDatabasePATH"
|
EG H. |
but thats besides the point
|
EG H. |
Testing new code now.
|
Nov 14 | 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.
|
Nov 14 | 8:25 PM |
EG H. |
Grrr. Still no luck with it.
|
EG H. |
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
|
Mark M. |
though it is a rather long list
|
EG H. |
hahaha
|
EG H. |
I'll try to get this right by Monday.
|
EG H. |
Speaking of to do lists.
|
EG H. |
I actually came out with my first app and it's a to do list.
|
EG H. |
hahaha
|
EG H. |
Pretty nifty though.
|
Mark M. |
cool!
|
Nov 14 | 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.
|
EG H. |
"Have To Do"
|
EG H. |
By "Cereal Bar Apps"
|
EG H. |
If you type in "Have To Do Cereal" I'm like number 3 on the list.
|
EG H. |
It's a to do list in your notifications.
|
EG H. |
I to have a hugggggggge to do list. But there are a couplee of things each day that I "Have To Do"
|
EG H. |
So it keeps bothering me until I say that I did it.
|
EG H. |
Not too shabby.
|
Mark M. |
apparently, this includes your homework, based on the screenshot :-)
|
EG H. |
Yes! hahaha.
|
EG H. |
Please tell me what you think honestly.
|
EG H. |
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.
|
EG H. |
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.
|
EG H. |
Thanks again
|
Mark M. |
you are very welcome
|
Mark M. |
next chat is Monday, 10am Eastern
|
EG H. |
You mentioned at the bbq that you're in Philly right?
|
EG H. |
East coast?
|
Mark M. |
Pennsylvania, though not Philly
|
Nov 14 | 8:35 PM |
EG H. |
Close enough. Hahaha. Yes, I'm from central jersey.
|
EG H. |
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 |