How to call # from program in android - android

I want to do this for my school project I want call from my app to show imei number so I want # also to be copied to phone call.But when I am executing the below code only the * is copied to phone call area
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + "*#06#"));
startActivity(intent);

in order to call USDD codes you have to use something like this :
String code = "*" + Uri.encode("#") + "06" + Uri.encode("#");
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + code)));
and don't forget to use the call permission in your manifest :
<uses-permission android:name="android.permission.CALL_PHONE"/>

Related

ACTION_CALL Intent getting rid of # at the end of number

The below code makes calls within android however, the # at the end of the number is removed and the android calls the number without it, is there a way to specify that android should keep the # at the end of the number cause I need it in this case?
Intent startCall = new Intent(Intent.ACTION_CALL);
Uri uri = Uri.parse("tel:*001203#");
startCall.setData(uri);
startActivity(startCall);
Android Manifest has the below permissions.
<uses-permission android:name="android.permission.CALL_PHONE"/>
Just use this snippet on clicking :
call.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String s = Uri.encode("*001203#");
Intent callIntent = new Intent(Intent.ACTION_DIAL);;
callIntent.setData(Uri.parse("tel:"+s));
startActivity(callIntent);
}
});
String hash = Uri.encode("#");
String ussd = "*" + hash + "001203" + hash;
startActivityForResult(new Intent("android.intent.action.CALL",Uri.parse("tel:" + ussd)), 1);
this is the workaround.

Android : How do I integrate whatsapp calling

Is there any way to direct call to a number by whatsapp from another application?
I have tried to redirect for messaging by using below code and is working fine.
Uri uri = Uri.parse("smsto:" + number);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));`
Is there any similar way for calling ?
I am not sure as I have not test this but hope this will work,
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + number));
callIntent.setPackage("com.whatsapp");
startActivity(callIntent);
And don't forget below permission in menifest file
<uses-permission android:name="android.permission.CALL_PHONE" />

Intent.ACTION_DIAL with number ending with #

So I'm trying to send a number via Intent.ACTION_DIAL ending with # i.e for example *123#. But when the Android Dialer app is started, there is only *123 (# is missing).
I'm using following code to trigger the Dial Application of Android.
Uri number = Uri.parse("tel:*124#");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
context.startActivity(callIntent);
Anticipated Thanks!!
.
You need to properly encode the hash tag (#). In your URL requests it should be %23, so replacing it with %23 will do the trick.
Uri number = Uri.parse("tel:*124%23");
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
context.startActivity(callIntent);
You can also let URI do the encoding:
String encodedPhoneNumber = String.format("tel:%s", Uri.encode("*1234#"));
Uri number = Uri.parse(encodedPhoneNumber);
Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
context.startActivity(callIntent);
The answer could be related with this link
initiate a phone call on android with special character #
This line could be the key
Uri.parse("tel:"+Uri.encode("*124#"));

how to make a call from my application?

Need to make calls from my application, without invoking the default dialer Activity, i.e. my application's activity should complete the dial-out, conversation and hang-up operations.
Note that the usual way of invoking the default dialer Activity done as follows, is not what I need:
String nber = phone.getText().toString();
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + nber));
startActivity(callIntent);
Try this
String nber = "tel:" + phone.getText().toString().trim();
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(nber));
startActivity(callIntent);
And give Manifest permission
<uses-permission android:name="android.permission.CALL_PHONE" />
Intent calltoDoctor = new Intent(Intent.ACTION_CALL);
calltoDoctor.setData(Uri.parse("tel:" + personalInformation.getEmgyno()));
startActivity(calltoDoctor);
Add the permission in manifest.
<uses-permission android:name="android.permission.CALL_PHONE" >
try this

Make USSD call in android

To check the balance first i have to make a call *xxx# and then i get a response with the multiple options to choose from and after i input the particular number i get the balance.
What code can i use for the same in my android app?
Dialing *xxx*x# is giving me error.
Below is my code which works fine for the *xxx# calls:
String encodedHash = Uri.encode("#");
String ussd = "*" + encodedHash + lCallNum + encodedHash;
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + ussd)));
This works for me:
private Uri ussdToCallableUri(String ussd) {
String uriString = "";
if(!ussd.startsWith("tel:"))
uriString += "tel:";
for(char c : ussd.toCharArray()) {
if(c == '#')
uriString += Uri.encode("#");
else
uriString += c;
}
return Uri.parse(uriString);
}
Then in work code:
Intent callIntent = new Intent(Intent.ACTION_CALL, ussdToCallableUri(yourUSSDCodeHere));
startActivity(callIntent);
Don't forget to add permission it will solve skype problem:P
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
String ussd = "*XXX*X" + Uri.encode("#");
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + ussd)));
this works perfect with me. just place the first bunch as it is then encode the # to make it have a complete *XXX*X#. this will definitely be of help
Important thing to remember :
If your are targeting Android Marshmallow (6.0) or higher then you need to request Manifest.permission.CALL_PHONE permission at runtime
Use this code, it works
Intent callIntent = new Intent(Intent.ACTION_CALL);
String ussdCode = "*" + 2 + Uri.encode("#");
callIntent.setData(Uri.parse("tel:" +ussdCode));
if (ActivityCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
startActivity(callIntent);
Add this line in Manifest file too
<uses-permission android:name="android.permission.CALL_PHONE" />
You can use this code. It works for me:
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(Uri.parse("tel:" + "*947") + Uri.encode("#")));
startActivity(intent);

Categories

Resources