I am trying to dial a number like *123*0xxxxxxxxxx# . And the 0xxxxxxxxxx portion would be got from the user input through an edit text.my code is here
EditText et1;
String ET1;
String pnd,encode_zero;
Button call;
Intent callIntent = new Intent(Intent.ACTION_CALL);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.call);
et1 = (EditText) findViewById(R.id.et1);
call = (Button) findViewById(R.id.btn_call);
ET1 = et1.getText().toString();
call.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pnd = Uri.encode("#");
encode_zero = Uri.encode("0");
callIntent.setData(Uri.parse("tel:*123*0" + ET1 + pnd));
startActivity(callIntent);
}
});
but when I run the app it ends with telling invalid number . that means I think the zero(0) is not considered. I have tried with this one too...
public void onClick(View v) {
pnd = Uri.encode("#");
encode_zero = Uri.encode("0");
callIntent.setData(Uri.parse("tel:*123*" + encode_zero + ET1 + pnd));
startActivity(callIntent);
}
but the result is all the same. Now what can I do ?
确保将此权限添加到清单
<uses-permission android:name="android.permission.CALL_PHONE" />
This code opens the phone dialer with the number on it -
String number = "*123*0123456#";
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + Uri.encode(number)));
if (ActivityCompat.checkSelfPermission(getBaseContext(), Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
startActivity(callIntent);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.