Created
June 2, 2012 14:21
-
-
Save hanigamal/2858612 to your computer and use it in GitHub Desktop.
Android: Dial A Number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Activity; | |
import android.content.Intent; | |
import android.net.Uri; | |
import android.os.Bundle; | |
import android.view.KeyEvent; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.LinearLayout; | |
public class DialANumber extends Activity { | |
EditText mEditText_number = null; | |
LinearLayout mLinearLayout_no_button = null; | |
Button mButton_dial = null; | |
/** Called when the activity is first created. */ | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
mLinearLayout_no_button = new LinearLayout(this); | |
mEditText_number = new EditText(this); | |
mEditText_number.setText("5551222"); | |
mLinearLayout_no_button.addView(mEditText_number); | |
mButton_dial = new Button(this); | |
mButton_dial.setText("Dial!"); | |
mLinearLayout_no_button.addView(mButton_dial); | |
mButton_dial.setOnClickListener(new View.OnClickListener() { | |
public void onClick(View v) { | |
performDial(); | |
} | |
}); | |
setContentView(mLinearLayout_no_button); | |
} | |
public boolean onKeyDown(int keyCode, KeyEvent event) { | |
if (keyCode == KeyEvent.KEYCODE_CALL) { | |
performDial(); | |
return true; | |
} | |
return false; | |
} | |
public void performDial(){ | |
if(mEditText_number!=null){ | |
try { | |
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + mEditText_number.getText()))); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
}//if | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment