开发者

Make a phone call without clicking phone call button in android

开发者 https://www.devze.com 2023-04-04 03:18 出处:网络
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

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

  1. Fire an intent ----> Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("Tel:(+12)123456789")); startActivity(intent);
  2. Add this permission to your manifest file ----->

And your ready to go....

0

精彩评论

暂无评论...
验证码 换一张
取 消