Android使用Intent实现拨打电话的动作

【Android使用Intent实现拨打电话的动作】宝剑锋从磨砺出,梅花香自苦寒来。这篇文章主要讲述Android使用Intent实现拨打电话的动作相关的知识,希望能为你提供帮助。
使用Intent实现打电话的动作,我们须要在 AnroidMainfest.xml中增加通话权限,打开这个文件,在application节点的前面增加以下内容

< uses-permission android:name="android.permission.CALL_PHONE" />

以下,使用Intent实现打电话的这个动作,看代码
Intent intent = new Intent(); intent.setAction(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:15100000000")); startActivity(intent);

我们能够将这段代码放在随意事件中,如button事件。这里举一个实例来实现。
Button btn = (Button)findViewById(R.id.button1); btn.setOnClickListener(new OnClickListener(){@Override public void onClick(View arg0) { // TODO Auto-generated method stub //TextView tv = (TextView)findViewById(R.id.textView1); //tv.setText("very good"); Intent intent = new Intent(); intent.setAction(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:15100000000")); startActivity(intent); } });

上例实现的是。点击buttonbtn以后触发打电话的动作,同一时候拨出电话关于用户权限问题,请移步 Android 中关于权限问题的介绍 Android permission 訪问权限一览 一文

    推荐阅读