Android使用Intent实现拨打电话的动作
生活随笔
收集整理的這篇文章主要介紹了
Android使用Intent实现拨打电话的动作
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
使用Intent實(shí)現(xiàn)打電話的動(dòng)作,我們需要在 AnroidMainfest.xml中加入通話權(quán)限,打開這個(gè)文件,在application節(jié)點(diǎn)的前面加入以下內(nèi)容
<uses-permission android:name="android.permission.CALL_PHONE" />
下面,使用Intent實(shí)現(xiàn)打電話的這個(gè)動(dòng)作,看代碼
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:15100000000"));
startActivity(intent);
我們可以將這段代碼放在任意事件中,如按鈕事件,這里舉一個(gè)實(shí)例來實(shí)現(xiàn)。
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);
}
});
上例實(shí)現(xiàn)的是,點(diǎn)擊按鈕btn以后觸發(fā)打電話的動(dòng)作,同時(shí)撥出電話 關(guān)于用戶權(quán)限問題,請移步 Android 中關(guān)于權(quán)限問題的介紹
Android permission 訪問權(quán)限一覽 一文
總結(jié)
以上是生活随笔為你收集整理的Android使用Intent实现拨打电话的动作的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android中JSON解析细解及实例
- 下一篇: Android permission 访