I want to display Number Dial Keypad (Phone Call) Programmatically on button click in android. Code is available for direct number dialing but I only need to show the dial keypa
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:9999999999"));
startActivity(intent);
For this we don't need to add any permission in AndroidManifest.xml
If you want to use it in non activity class then create a function like this :
package bp;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import session.MyApplication;
/**
* Created by Atiar Talukdar on 7/11/2019.
*/
public class Utils {
public static void openDialPad(Activity activity, String phoneNumber) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + phoneNumber));
activity.startActivity(intent);
}
}
and then call from anywhare in like :
Utils.openDialPad(getActivity(),data.getContactNo());
or
Utils.openDialPad(this,data.getContactNo());
Make button or any widget example : button1
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:"+button1.getText().toString().trim()));
startActivity(callIntent);
}
});
Add permission in manifest :
<uses-permission android:name="android.permission.CALL_PHONE" />
public void openDialPad(String phoneNumber) {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse(phoneNumber));
startActivity(intent);
}
This is different, but if you want to access your dialer pad by clicking a number, in your xml, declare the autolink attribute
android:autoLink="phone"
Intent intent = new Intent(Intent.ACTION_DIAL);
startActivity(intent);