Service send text and make background call

cammel8

Member
Licensed User
Longtime User
First I would like to apologize for the length; however, I want to be as clear as I can.

Ok first off I have went through the tutorial on services here:
http://www.b4x.com/forum/basic4android-getting-started-tutorials/7542-service-modules.html#post42973
I searched and read a bunch of stuff on the forums about services and sadly I still don't understand how to use them. I don't understand how to start and stop the service, and how to pass variables to them. I don't know what the problem is, usually I get this stuff easily.

OK here is what I am trying to do. I am making a Dead Mans Switch. Basically lets say you know you are about to go into a bad situation, say a dark alley, or a kid walking home alone. You bring up this app and start the panic mode. Put your finger on the screen and hold it there. As long as your finger is on the screen, you are fine, once you take your finger off the screen, you have three seconds to triple tap the screen or it will:
A.) Send out a text to your emergency number warning them you are in trouble.
B.) Send them your GPS coordinates every set amount of seconds.
C.) Open up a call in the background to the same number with the speaker shut off, and the screen showing nothing, and the phone showing nothing that indicates a call is in progress.
D.) Show a innocuous message in the status bar area saying you have a text message from someone, like your mom, and when you bring up the message, it is the way to enter a password to disable the panic mode.
E.) Close the program so it is no longer running, and allow just the service to stay running, and show the home screen.
F.) While the service is running, send a text message, according to what was set up in settings, every x amount of minutes until the service is shut off or the phone dies.

I have gotten the panic part to work, and can send text messages, but not through a service yet. I have it getting the GPS coordinates, but again, don't know how to send them to the service. I can get it to call, but it shows the dial program and stays in focus, and shows that it is in a call. And I have not been able to figure out how to put the message in the status bar, but I'm sure if I can figure out how to use services, I can figure it out using this post.
http://www.b4x.com/forum/basic4android-getting-started-tutorials/7572-downloading-files-using-service-module.html

So , my question is, is it possible to do all of what I want to do? I am starting to think that the call part of it wont be able to be done in the background, and the best I am going to be able to do is make the call then minimize the dial program so all I have is the phone icon in the task bar. And as far as shutting off the speaker, I am guessing my best bet on that is turning down the in call volume. Is that true?

My second question is, how do I pass variables to the service? Right now I have, PhoneNumber, SMSmessage, Lon, Lat, and GPSTime as variables that I have to pass to the service. And then once I do pass the variables, how do I call the service, and have it use those variables I passed it?

Im not looking for someone to do the work for me. I really want to learn, but I am having a hard time following the tutorial. Is there anyone that has a sample of something they have done that I could look at the code and see first hand how something like this is done? My biggest problem, I think, is that in most posts, I get snippets of code and never actually see the full code, to fully understand what is going on.

I am attaching the project as I have it right now. I have commented out the line where it sends a text, because for some reason I am getting a nullPointerexception. It must have happened after I changed something. but everything else is working fine.

Any help anyone could give me would be greatly appreciated.

Thank you in advance.
George
 

thedesolatesoul

Expert
Licensed User
Longtime User
Services are the perfect solution for you.
Short answers:
Do all your processing (sending texts etc) under Service_Start.
At the end schedule the next run with StartServiceAt.
You can pass values to the service with Global variables. That should be dead simple.

Sent from my GT-I9000 using Tapatalk
 
Upvote 0

cammel8

Member
Licensed User
Longtime User
Services are the perfect solution for you.
Short answers:
Do all your processing (sending texts etc) under Service_Start.
At the end schedule the next run with StartServiceAt.
You can pass values to the service with Global variables. That should be dead simple.

Sent from my GT-I9000 using Tapatalk

You freaking rock. Thank you! Don't know what my big problem was, I just didn't get it. I think i got it now. Using what you gave me I figured out what I needed to so far. Seems pretty easy.

Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you, Thank you!

George
 
Upvote 0

cammel8

Member
Licensed User
Longtime User
OK, thanks to thedesolatesoul, I have figured out and implemented almost everything. However, I still haven't figured out the phone call part as of yet. Is there a way to make a background call? And if there is how? And is there a way to set the in call volume of the headset?
 
Upvote 0
Top