0

I am trying to implement calling facility from my app. When some condition is true, I am hiding my caller id by adding #31# before my number. Although if #31# is not added, call is made perfectly allright but when #31# is added, blank screen pops up, as if the Phone app is loading, and my application screen comes back. My code snippet is this

        String ph = "123456789";            
        String phNumber;
        if (hideCallerId) {
            phNumber = "#31#" + ph;
        }
        else {
            phNumber = ph; 
        }

        Intent intent = new Intent(Intent.ACTION_CALL);
        intent.setData(Uri.parse("tel:"+phNumber));
        startActivity(intent);

Case 1: when phNumber is 123456789, then call is made without problem.

Case 2: when phNumber is #31#123456789, then blank screen pops up and user comes back to my application screen.

Although when I am dialing from my device using #31#123456789, call is successfully made. What I am missing out. Can anybody help me out.

Links didn't helped me Link1. Thanks in advance.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Android
  • 3,828
  • 9
  • 46
  • 79

3 Answers3

2

This isn't really an answer but my rep isn't high enough for a comment. Is there any chance you have phnumber declared as an int or anything? Maybe the #'s are messing it up?

If that doesn't work have you tried using ACTION_DIAL? the android developer site has more info on the differences between them here. Hope it helps.

boundless08
  • 303
  • 4
  • 17
  • For that matter, if you don't need the original number ("123456789") by itself you can use just the one variable. Bit simpler but it won't help with your problem! – Alex Oct 25 '12 at 10:07
  • Hey boundless. Thanks for replying. Ya i will check this out. Glad u mentioned what may be wrong. And Nope my phnumber is a string variable. and also dial is taking me to dial screen, its not dialing the number which i am passing. And I need to dial the number from my app screen. – Android Oct 25 '12 at 10:07
  • Although your answer is not what I needed but still points to some serious stuff thus +1 – Android Oct 25 '12 at 10:38
1

You simply have to encode the phone number.

String phonenumber = "03012345,1234,#31#,98765"; // , = pauses
encodedPhonenumber = URLEncoder.encode(phonenumber, "UTF-8");
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + encodedPhonenumber)));

You may want to have a look at this one. Not able to make a call when #31# is added

Community
  • 1
  • 1
Android
  • 3,828
  • 9
  • 46
  • 79
  • Ya its working. But can you explain me why do we need to encode it. I am not getting why do we need to do this, but in dial simple inputting it is enabling us to dial – Android Oct 25 '12 at 11:16
  • Can't point out the exact reason but I guess android finds some difficulty in reading '#'. thus need to be encoded. – Android Oct 25 '12 at 11:49
1

You need to encode the '#' because it behaves like a dial command, then if you set your action call intent data with a number starting with '#', it will instead call a blank number, trying to dial a number like 8488449#848 if not encoded will dial 8488449 that's why you need to encode at least the '#' symbol with Uri.encode("#") for example to dial 8488449#848, i will do the following: startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:8488449"+Uri.encode("#")+"848"));

al kaj
  • 119
  • 1
  • 9