views:

116

answers:

2

I'm trying to create an application that can use the android as a fax machine, IE Send a picture as a fax or receive a fax and save as a picture. So far I'm starting from the ground up and making sure I can intercept a call at the users discretion. I have an Receiver registered in the Manifest of my program with a filter of Phone_State which flags when the state has changed(IE incoming call).

So on my BroadcastReceiver I'm trying to have an AlertDialog popup prompting the user to either accept as fax or call but the AlertDialog seems to throw a android.view.WindowManager$BadTokenException Error when it has an incoming call. My code is just simple an onReceive(context arg0, intent arg1) and I pass the arg0 to the AlertDialog...

The full error message is below

08-08 00:16:14.315: ERROR/AndroidRuntime(275): java.lang.RuntimeException: Unable to start receiver com.android.fax.IncomingFax: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
08-08 00:16:14.315: ERROR/AndroidRuntime(275):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2550)
08-08 00:16:14.315: ERROR/AndroidRuntime(275):     at android.app.ActivityThread.access$3000(ActivityThread.java:116)
08-08 00:16:14.315: ERROR/AndroidRuntime(275):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1843)

From what I have seen in the AlertDialog code, it passes the context as well as a Window and WindowManager, which I believe is why it's crashing, is there a better way or something else I should be using which might overlay the call screen?

+1  A: 

First, you can't get to the in-call audio stream from Android. With that limitation, I have no idea how you are going to receive a fax.

With respect to your error, a manifest-registered BroadcastReceiver is not an Activity, and so it cannot create a dialog. You could, in principle, call startActivity() to start up an Activity (perhaps one themed like a dialog), but I do not know whether or not it would appear over the in-call screen.

CommonsWare
Regarding the first comment: Yeah, that's what I figured, I couldn't find any documentation on that.Second: Okay, I didn't know that it needed an activity, just a context. Thanks for the info.
Nicholas
@Nicholas: for most GUI-related stuff, you need an `Activity`, even if the method signature only requires a `Context`.
CommonsWare
Well Yeah, but you can do a toast without one, so I assumed something similar like a Dialog wouldn't need it. But I did check out the Base Class Dialog and it does say it needs an activity, should have check that out first.
Nicholas
A: 

Hello, could you please tell more about how create an Activity from the broadcastreceiver? Thanks a lot

Julie