how to make a call from my application? - android

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

Related

How to call # from program in 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"/>

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" />

No Activity found to handle Intent { act=android.intent.action.DIAL }

I want to open my phone dialer .But it shows error. I have declared permissions for CALL_PHONE on Android Manifest and also declared class in Android Manifest.
case R.id.action_call:
Log.d("Action_call","INside Action call");
Intent dialer = new Intent(Intent.ACTION_DIAL);
startActivity(dialer);
return true;
You don't need any permissions for ACTION_DIAL Intent. So remove CALL_PHONE permission from AndroidManifest.xml.
You have not pass any number to fire dial Intent.
Use tel: followed by the phone number as the value passed to Uri.parse():
Try this code.
String number = "1234567890";
Uri number = Uri.parse("tel:" + number);
Intent dial = new Intent(Intent.ACTION_DIAL);
dial.setData(number);
startActivity(dial);
EDIT:
You can first check whether telephony is supported on device
private boolean isTelephonyEnabled(){
TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
return tm != null && tm.getSimState()==TelephonyManager.SIM_STATE_READY
}
I hope it helps!
Use Uri to parse number..
Intent call = new Intent(Intent.ACTION_DIAL);
call.setData(Uri.parse("tel:"+phone)); //String phone
startActivity(call);
Use try/catch.
Use Uri to parse number.
Don't need any permissions for ACTION_DIAL intent.
try{
Intent call_intent = new Intent(Intent.ACTION_DIAL);
call_intent.setData(Uri.parse("tel:"+phone_number));
startActivity(call_intent);
}catch(Exception e){
}

Using intent.Action_call for user inputted number

Help me modify with necessary changes needed to use the value/string(number) passed by user for phone-calling that string itself
Intent phnIntent = new Intent(Intent.ACTION_CALL);
phnIntent.setData(Uri.parse("tel:+91987654321"));
you can use like this :
String strTelNo = "+91987654321";
Intent intent = new Intent("android.intent.action.CALL");
Uri data = Uri.parse("tel:"+ strTelNo );
intent.setData(data);
startActivity(intent);
Try this link.
Make sure you add the necessary permission in the Android Manifest.
<uses-permission android:name="android.permission.CALL_PHONE" />
Just add the line startActivity(phnIntent);
EDIT:
Activity A
Intent someIntent = new Intent(A.this, B.class);
someIntent.putExtra("phoneNumber", number);
startAcitivty(someIntent);
Acitivity B
Bundle extras = getIntent().getExtras();
String number = extras.getInt("phoneNumber");
Use the number string to make the call.

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