views:

49

answers:

1

Id like to enable bluetooth like in this example.

However my class isnt a Activity but a Service and therefore I can't call startActivityForResult. How can i solve this problem?. I know there are other questions that have been answered like

http://stackoverflow.com/questions/2848775/use-startactivityforresult-from-non-activity

but this doesn't solve my problem because my application consists of the service and nothing else.

+1  A: 

Unfortunately you can't do that.

The only solution I found (hack) is to first open an Activity with a Dialog style and then do the call there.

Macarse
Ok then i tried to use broadcast receivers. however there i can only catch the intents when the state changed, but if bluetooth is disabled and i want to leaf it disabled, then the state doesn't changes and i'm never notified...
Roflcoptr
Sorry, I don't understand what you are saying. Can you re-explain?
Macarse
Since I can't use startActivityForResult() I tried to use BroadcastReceivers to catch the events if bluetooth state changed. Unfortunately the bluetooth state only changes if e.g. bluetooth isn't enabled and the user clicks yes to enable it. Then my broadcastReceiver gets informed. But if bluetooth isn't enabled and the user clicks no, the the bluetooth state does not change and therefore my broadcastReceiver isn't notified.
Roflcoptr
Don't you want to enable BlueTooth? What I am saying is that you can start an activity in the service and then calling startActivityForResult.
Macarse
hmm yes maybe this will work ;) thx!
Roflcoptr