标签:
Action<uses-permission android:name="android.permission.CALL_PHONE"/>
第一步在MainActivity:
package com.example.intent_intentFilter; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { private EditText et_phoneNumber; private Button btn_dial,btn_call; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et_phoneNumber = (EditText) findViewById(R.id.et_phonenumber); btn_call = (Button) findViewById(R.id.btn_call); btn_dial = (Button) findViewById(R.id.btn_dial); InnerOnClickListener listener = new InnerOnClickListener(); btn_call.setOnClickListener(listener); btn_dial.setOnClickListener(listener); } private class InnerOnClickListener implements OnClickListener{ @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(); String phonenumber = et_phoneNumber.getText().toString(); //Data的字符串格式为:tel://10086 intent.setData(Uri.parse("tel://"+phonenumber)); switch (v.getId()) { case R.id.btn_call: intent.setAction(Intent.ACTION_CALL); break; case R.id.btn_dial: intent.setAction(Intent.ACTION_DIAL); break; default: break; } } } }第二步:在配置文件中加入权限:
<uses-permission android:name="android.permission.CALL_PHONE"/>
标签:
原文地址:http://blog.csdn.net/wei_chong_chong/article/details/50434561