如何在Android中打電話含代碼

如何在Android中打電話

通過意圖(intent)我們可以在安卓中打電話。愛掏網(wǎng) - it200.com您只需要編寫三行代碼就能打電話。愛掏網(wǎng) - it200.com

Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+8802177690));//change the number
startActivity(callIntent);

Android中的電話呼叫示例

activity_main.xml

從工具欄中拖動(dòng)EditText和Button,現(xiàn)在activity_main.xml文件將如下所示:

<RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="118dp"
        android:text="Call" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="25dp"
        android:ems="10" />

</RelativeLayout>

寫入Android-Manifest.xml文件中的權(quán)限代碼

您需要按照下面的方式寫入CALL_PHONE權(quán)限:

<uses-permission android:name="android.permission.CALL_PHONE" />
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:androclass="http://schemas.android.com/apk/res/android"
    package="com.example.phonecall"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <uses-permission android:name="android.permission.CALL_PHONE" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.phonecall.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Activity類

讓我們編寫代碼,通過意圖來進(jìn)行電話呼叫。愛掏網(wǎng) - it200.com

package com.example.phonecall;

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 {
    EditText edittext1;
    Button button1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Getting the edittext and button instance
        edittext1=(EditText)findViewById(R.id.editText1);
        button1=(Button)findViewById(R.id.button1);

        //Performing action on button click
        button1.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View arg0) {
                String number=edittext1.getText().toString();
                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:"+number));
                startActivity(callIntent);
            }

        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}

在真實(shí)設(shè)備(例如手機(jī))上安裝和運(yùn)行apk文件以進(jìn)行電話呼叫。愛掏網(wǎng) - it200.com

輸出:

聲明:所有內(nèi)容來自互聯(lián)網(wǎng)搜索結(jié)果,不保證100%準(zhǔn)確性,僅供參考。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。
發(fā)表評(píng)論
更多 網(wǎng)友評(píng)論0 條評(píng)論)
暫無評(píng)論

返回頂部

主站蜘蛛池模板: www.欧美xxx| 天堂а√在线中文在线| 欧美成a人片在线观看| 老司机aⅴ在线精品导航| 1000部又爽又黄的做黄禁片| 一区二区国产在线播放| 久久精品一区二区| 亚洲成av人影片在线观看| 全球中文成人在线| 国产va免费精品观看精品| 国产猛烈高潮尖叫视频免费| 国语对白刺激做受xxxxx在线| 成人黄色小说网站| 日本漫画大全彩漫| 最近2019免费中文字幕视频三 | 在线观看免费人成视频| 性色av免费观看| 成人毛片18女人毛片免费视频未| 曰本一区二区三区| 欧美人与动交片免费播放| 欧美老熟妇乱大交XXXXX| 男女后进式猛烈XX00动态图片| 老熟女高潮一区二区三区| 都市激情亚洲色图| 里番全彩本子库acg污妖王| 国产精品亚洲四区在线观看| 你懂的在线播放| 2021午夜国产精品福利| 777爽死你无码免费看一二区| av无码一区二区三区| japanesehdfree人妻无码| 一二三四日本视频中文| 不卡高清av手机在线观看| 中文字幕乱码中文乱码51精品 | 欧美综合中文字幕久久| 毛片基地免费观看| 欧美日韩一区二区三区在线观看视频| 欧美色欧美亚洲另类二区| 欧美日韩亚洲一区二区三区| 欧美性大战久久久久久| 最近免费中文字幕4|