我正在尝试拨打* 123 * 0xxxxxxxxxx#等号码。并且0xxxxxxxxxx部分将通过编辑文本从用户输入获得。我的代码在这里
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);
}
});
但是当我运行应用程序时,它会告诉无效的号码。这意味着我认为不考虑零(0)。我也试过这个......
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);
}
但结果完全相同。 现在我该怎么办?
答案 0 :(得分:0)
确保将此权限添加到清单
<uses-permission android:name="android.permission.CALL_PHONE" />
答案 1 :(得分:0)
此代码打开带有号码的电话拨号器 -
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);