Office Hours — Today, November 3

Nov 3
7:05 PM
Mark M.
has entered the room
Nov 3
7:50 PM
Mark M.
turned on guest access
Test U.
has entered the room
Test U.
has left the room
Nov 3
7:55 PM
Bill O.
has entered the room
Bill O.
Hello!
Mark M.
Howdy!
Bill O.
So how do you want to play in here?
Mark M.
You ask questions. I give answers, or at least snappy comebacks.
Bill O.
OK - I've got a question, ready?
Mark M.
Fire away!
Bill O.
I've got an AsyncTask:
Bill O.
protected Void doInBackground(Void... params) {
Bill O.
File oldPhoto = new File(Environment.getExternalStorageDirectory(), "WIIA-old.jpg");
Nov 3
8:00 PM
Bill O.
View paste
File newPhoto = new File(Environment.getExternalStorageDirectory(),
				"WIIA-new.jpg");
Bill O.
double distance;
Mark M.
You may want to use http://gist.github.com/ or something for code fragments -- not sure how well that's going to turn out directly in the chat.
Bill O.
distance = ImageComparator.naiveSimilarityFinder(oldPhoto, newPhoto); ... yeah :)
Bill O.
this part works fine ... I get my distance (diff between the two images)
Bill O.
then I try to send an mms ...
Bill O.
Looper.prepare();
Bill O.
MmsSender ms = new MmsSender();
Bill O.
ms.sendMMS(phoneNumber);
Bill O.
(phone number is created above, but being brief here)
Bill O.
View paste (34 more lines)
public class MmsSender extends Activity {
	private static final String subject = "WIIA Alarm";
	private static final String body = "WIIA Alarm, photo is included.\n";
//	private Activity mActivity;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	
//	public void sendMMS(String phoneNumber, String subject, String body) {
	public void sendMMS(String phoneNumber) {
		Log.e("MmsSender", "phoneNumber is " + phoneNumber);
		Log.e("MmsSender", "subject is " + subject);
...
Bill O.
this returns:
Bill O.
View paste
11-03 19:53:12.937: ERROR/AndroidRuntime(759): Uncaught handler: thread AsyncTask #2 exiting due to uncaught exception
Bill O.
View paste
11-03 19:53:12.947: ERROR/AndroidRuntime(759): java.lang.RuntimeException: An error occured while executing doInBackground()
Bill O.
11-03 19:53:12.947: ERROR/AndroidRuntime(759): at android.os.AsyncTask$3.done(AsyncTask.java:200)
Bill O.
...
Nov 3
8:05 PM
Bill O.
11-03 19:53:12.947: ERROR/AndroidRuntime(759): Caused by: java.lang.NullPointerException
Nov 3
8:05 PM
Bill O.
11-03 19:53:12.947: ERROR/AndroidRuntime(759): at android.app.Activity.startActivityForResult(Activity.java:2656)
Bill O.
11-03 19:53:12.947: ERROR/AndroidRuntime(759): at android.app.Activity.startActivity(Activity.java:2700)
Bill O.
11-03 19:53:12.947: ERROR/AndroidRuntime(759): at com.androidsecurity.wiia.MmsSender.sendMMSFromUri(MmsSender.java:42)
Bill O.
where line 42 is: startActivity(intent);
Bill O.
I am trying to send this mms without user interaction.
Mark M.
Oh, in that case, can't SmsManager do that?
Bill O.
Ummm, OK :)
Mark M.
I don't think you can start an activity from a background thread safely.
Mark M.
Oh, wait.
Mark M.
Looks like SmsManager only does SMS, not MMS
Mark M.
Try moving your code that does the startActivityForResult() to the onPostExecute() portion of your AsyncTask, instead of having it in doInBackground().
Bill O.
That makes sense (I think) ... any way to create an mms directly from a background thread? I tried that first.
Mark M.
If it were SMS, SmsManager should be able to do that, I would think.
Mark M.
MMS...I don't see how else to send one.
Bill O.
Yeah, but I need to attach a jpg
Nov 3
8:10 PM
Mark M.
Precisely.
Mark M.
Which is why the ACTION_SENDTO is perhaps your only shot of sending an MMS without user interaction...and I don't think you can do that from a background thread.
Bill O.
So is it possible to send an mms in a background thread? ... just answered my question, :)
Darin P.
has entered the room
Bill O.
Any workaround? (Hi Darin)
Mark M.
Hi, Darin!
Mark M.
I'm not an expert at MMS by any stretch of the imagination.
Bill O.
Me either. :)
Mark M.
Unless there's a way you can use SmsMessage to craft an MMS, I don't think there are any public APIs for MMS.
Mark M.
Oh, and SmsMessage seems to be read-only, probably for inbound messages.
Mark M.
So, I suspect you're stuck needing the UI thread.
Bill O.
Me either ... doesn't an sms automagically become an mms if it exceeds sms limitations?
Mark M.
Beats me.
Mark M.
SmsManager has sendMultipartTextMessage(), which suggests otherwise.
Bill O.
I really dislike this project ... can't wait to be past it.
Nov 3
8:15 PM
Bill O.
Don't want to hog the room, so I'll defer to Darin.
Bill O.
Any way to grab a copy of these chats?
Mark M.
I think I can.
Mark M.
I'm not sure what guests see -- do you see a "Files, Transcripts, & Search" tab at the top?
Bill O.
Great! Nope.
Mark M.
I'll see what I can do about posting the transcript after the office hours are over.
Bill O.
Thanks!
Mark M.
This is yet another reason why, sometime in the future, I suspect I'll be moving this to Google Wave.
Bill O.
This is a great idea ... hope enough people join in to make it worth your while.
Nov 3
8:20 PM
Mark M.
It'll take time.
Mark M.
I'm certainly up for more questions from either of you.
Bill O.
If Darin doesn't have a question yet, can we get back to: "So, I suspect you're stuck needing the UI thread." ... how would that work?
Mark M.
Just call the MMS-sending logic from onPostExecute() in your AsyncTask.
Mark M.
Right now, it would appear to be invoked from doInBackground(), per your errors.
Bill O.
Brilliant!
Darin P.
has left the room
Bill O.
Now I really need a copy of this. :)
Mark M.
Yeah, copy/paste doesn't seem to work well, at least in Firefox
Bill O.
funny you should say that ... it's exactly what I'm doing.
Mark M.
I'm sure I can save the transcript, it's mostly a question of how much the transcript might rely upon relative CSS and nonsense like that, which would make posting it elsewhere tricky.
Nov 3
8:25 PM
Bill O.
So would I place onPostExecute() inside the protected Void doInBackground(Void... params) { ...}?
Mark M.
No, onPostExecute() is a peer of doInBackground()
Mark M.
It's another method you can override in your AsyncTask subclass
Bill O.
Have to read up on that then ... pdf/chapter you recommend?
Mark M.
Take a peek at _The Busy Coder's Guide to Android Development_, Version 2.1, page 212
Bill O.
You're amazing!
Mark M.
Um, no, I'm just Mark.
Bill O.
maybe right now
Bill O.
I'll check out the reference; thanks and best of luck with the Office hours. I know I'll be a regular. ;)
Mark M.
Sounds good. The office hours themselves will tend to be the same days of the week and times -- just a matter of whether I am available any given week.
Mark M.
I'll be announcing them on cw-android, and the scheduled ones will always be on your Warescription page.
Bill O.
Can't wait for an interesting project that actually leverages android's capabilities rather than fighting it tooth and nail.
Nov 3
8:30 PM
Mark M.
Androids have teeth?
Mark M.
Gonna have to watch out the next time I walk by the one building in the Googleplex...
Bill O.
nights are best for me ... mornings not so much.
Bill O.
need to chew on that. :)
Mark M.
The morning ones are for Europe and US East Coast. The evening ones are for US West Coast and Asia/Oceania
Mark M.
"spanning the globe, to bring you a constant variety of...er...Android stuff"
Bill O.
I work 9-5, ET through PT
Bill O.
BTW, how did the sprint dev session go?
Mark M.
Depends on how you look at it.
Mark M.
On the one hand, I ran into technical difficulties.
Bill O.
how about stright on?
Bill O.
computers ... modern inconveniences.
Mark M.
Hotel WiFi interjected its own page before redirecting you to the real destination -- OK for browsers, but that wreaks havoc on Web service APIs.
Mark M.
Hence, attendees could only run the app if they used the free Hero phones...and not everyone was in position to be hooking those up.
Mark M.
That and a few other minor challenges meant I wasn't terribly happy.
Nov 3
8:35 PM
Mark M.
On the other hand, Palm ran a WebOS session opposite ours, and we outdrew them by a preposterous margin.
Bill O.
I just have a g1 ... any issues developing on that and running on another phone?
Mark M.
Admittedly, a lot of that was the Hero giveaway, but we still had nearly 400 people at the outset.
Bill O.
400 ... sounds packed.
Mark M.
Developing on a G1 and deploying elsewhere should be fine in the abstract.
Mark M.
Screen sizes, Android versions, and minor hardware quirks will affect you no matter what you use for development.
Mark M.
Which is why I have all-new material on those topics in the next edition of _The Busy Coder's Guide to Android Development_
Mark M.
(hopefully shipping in < 1 week)
Bill O.
sort of like: "In theory, there is no difference between theory and praactice ... in practice, there is"
Bill O.
looking forward to that update.
Nov 3
8:40 PM
Bill O.
Well, it's getting close to miller time. Thanks so much for your insights! I'll no doubt be posting on cw-android if I run into any more problems. Ciao for now and keep up the good fight!
Mark M.
Enjoy your evening!
Bill O.
U2
Bill O.
has left the room
Nov 3
8:55 PM
Mark M.
turned off guest access
 

Office Hours

People in this transcript

  • Bill Ostaski
  • Darin Pope
  • Mark Murphy
  • Test User
Adblock