android 撥號

docomo發表於2014-07-17
public class CallActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button button = (Button) this.findViewById(R.id.button1);
        button.setOnClickListener(new ButtonOnClickListener());
    }
    
    private final class ButtonOnClickListener implements View.OnClickListener{

		@Override
		public void onClick(View v) {
			EditText mobileText = (EditText) findViewById(R.id.moblie);
			String number = mobileText.getText().toString();
			Intent intent = new Intent();
			intent.setAction("android.intent.action.CALL");
			intent.addCategory("android.intent.category.DEFAULT");
			intent.setData(Uri.parse("tel:" + number));
			startActivity(intent); //註冊android.intent.category.DEFAULT
			
		}
    	
    }
}
 
所需許可權 :<uses-permission android:name="android.permission.CALL_PHONE" />

相關文章