0

Hi I'm making an application to automate/activate call forwarding via sms all are working except of parsing some characters for the call forwarding code..

this is my code to execute the call forwarding code which is documented here: http://en.wikipedia.org/wiki/Call_forwarding#Keypad_codes

Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:"+Uri.encode("#")+Uri.encode("#")+"21"+Uri.encode("#")));
                ((Intent)callIntent).addFlags(268435456);
                this.context.startActivity((Intent)callIntent);

the code to cancel the call is ##21# but my application always got an error and looks like it cannot read my command as posted above but if I will dial it manually it is fine..

mboy
  • 744
  • 7
  • 17
  • What is the ##21# doing? Why not use callIntent.setData(Uri.parse("tel:268435456")); – JustinDanielson Jan 30 '12 at 18:30
  • @JustinDanielson that is a keypad codes for unconditional call forwarding. ##21# is the code to dial if you want to cancel it I found that here : [Call_forwarding#Keypad_codes](http://en.wikipedia.org/wiki/Call_forwarding#Keypad_codes) this line is working fine `callIntent.setData(Uri.parse("tel:268435456"));` but if I used "#" it will not work the phone prompts an error code. the code to dial if you want to forward all your calls is this **21*# and if you want to cancel the call forwarding to that number, simply dial this code ##21# And that's what I am trying to do. – mboy Jan 31 '12 at 02:17

1 Answers1

1

Try using ACTION_DIAL rather than ACTION_CALL for the **21* and ##21#.
Check out this link as well, I think it addresses your problem specifically.

Here's the TLDR:

String uri = "**21*268435456#";   // ##21#268435456#  
Intent intent = new Intent(Intent.ACTION_DIAL); // ACTION_CALL  
Uri uri2 = Uri.fromParts("tel", uri, "#");  
intent.setData(uri2);  
startActivity(intent);  
JustinDanielson
  • 3,155
  • 1
  • 19
  • 26
  • wow..awesome! I will try this and let you know! .. Thank you so much – mboy Feb 01 '12 at 12:48
  • Is there any way to automate the pressing of call key/green key? because it only dial the specified number and does not initiate a call.. – mboy Feb 02 '12 at 02:05
  • ACTION_CALL automates the call and ACTION_DIAL does just the dialing. You could try doing ACTION_CALL with the phone number, then while the call is going, do ACTION_DIAL with ##21#. You don't actually call ##21#, I think you dial is while the phone call is active to that number. I'm not entirely sure. If it works, let me know. Have you tried putting 21 in the fragment field? tel:phonenumber#21 and use that for ACTION_CALL or ACTION_DIAL – JustinDanielson Feb 02 '12 at 18:56
  • I still dont understand why this code doesn't work.. I keep on getting "call forwarding rejected. Unconditionally for all basic services" but if I will do it manually forwarding works.. – mboy Jun 19 '12 at 16:56
  • btw the code is inside in a broadcast receiver.. I am waiting sms to activate call forwarding.. the code works if i put a very big delay after the startactivity. startActivity(intent);   Thread.sleep(20000); is there any good solution for this problem? very big delay is not a good one.. :( – mboy Jun 19 '12 at 17:31
  • perhaps have the broadcast receiver start a service and send the service the information it needs through intent.putExtras(...). What progress have you made so far? – JustinDanielson Jun 19 '12 at 22:46
  • yes.. that is what I am going to study next how to start a service.. :) btw, I am already using the code with the delay.. https://gist.github.com/2958067 – mboy Jun 20 '12 at 04:03
  • does the delay give the operating system time to register a call is being made? maybe you can register a 2nd broadcast receiver to listen for the broadcast when a call is initiated? – JustinDanielson Jun 20 '12 at 04:36
  • Yes I think because Of the delay the call is being completed and the call forwarding is successful. You are suggesting another broadcast receiver.. hmmmmm I think that's nice... Any advance notes you can suggest or some hints then I will study that.. ;) – mboy Jun 20 '12 at 09:35
  • I'm not sure. Take a look at the different intent filters. There may be one that you can use to do call forwarding at the right time. Maybe this one? http://developer.android.com/reference/android/content/Intent.html#ACTION_ANSWER – JustinDanielson Jun 20 '12 at 20:38
  • http://stackoverflow.com/questions/5571249/how-do-i-retrieve-the-incoming-phone-calls-number-while-ringing-and-store-it-in – JustinDanielson Jun 20 '12 at 20:40
  • I found problem in using the delay I think it is causing the call loop.. it will repeat the action for sometime.. lol .. – mboy Jun 22 '12 at 09:54