I want to creat an Android app that can get phone number from a text file then make a phone call immediatelly without clicking any extra button. But, i find no way to do that. All samples on internet use the default call button to make a phone.
here is the code i used
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_CALL) {
performDial();
return true;
}
return false;
}
public void performDial(){
if(edittext.getText()!=null){
try {
startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + edi开发者_如何学JAVAttext.getText())));
} catch (Exception e) {
e.printStackTrace();
}
}//if
}
Thanks in advance
First, I do not know if you can get the KEYCODE_CALL
event or not in onKeyDown()
.
Second, use ACTION_CALL
instead of ACTION_DIAL
. You will need to hold the CALL_PHONE
permission for this to work.
It is very Simple. Do it like this ---->
- Fire an intent ----> Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("Tel:(+12)123456789")); startActivity(intent);
- Add this permission to your manifest file ----->
And your ready to go....
精彩评论