• Android开发实例:打电话


    1.首先建立一个android工程Phone  这里不再演示

    PhoneActivity.java文件如下:

    package jiao.jiao;

    import android.app.Activity;

    import android.content.Intent;

    import android.net.Uri;

    import android.os.Bundle;

    import android.view.View;

    import android.widget.Button;

    import android.widget.EditText;

    public class PhoneActivity extends Activity {

        /** Called when the activity is first created. */

    private EditText editText;

    private Button button;

        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

        editText= (EditText)this.findViewById(R.id.editText);

        button = (Button)this.findViewById(R.id.call);

        button.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {

    String phoneNum =editText.getText().toString();

    Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phoneNum));

    PhoneActivity.this.startActivity(intent);

    }

    });

        }

    }

    main.xml文件如下:

    xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

        android:orientation="vertical"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        >

    <TextView  

          android:layout_width="wrap_content" 

         android:layout_height="wrap_content" 

         android:text="@string/hello"

         />

         <EditText

          android:layout_width="fill_parent" 

         android:layout_height="wrap_content" 

         android:id="@+id/editText"

          />

         <Button

          android:layout_width="wrap_content" 

         android:layout_height="wrap_content"

         android:id="@+id/call"

         android:text="@string/call_button" 

          />

        

    LinearLayout>

    strings.xml

    xml version="1.0" encoding="utf-8"?>

    <resources>

        <string name="hello">打电话string>

        <string name="app_name">Phonestring>

        <string name="call_button">打电话string>

    resources>

    最后要加一个打电话的权限

    在工程中res->AndroidManifest.xml中

     点击Add-----

     点击Uses Permission-----

    然后选择

    这样就可以运行了!

  • 相关阅读:
    爬取任意百度贴吧评论(可直接Copy)
    STM32_HAL_I2C_串行接口
    【PHP实现微信公众平台开发—基础篇】第2章 微信公众账号及申请流程详解
    ubuntu永久修改mac地址
    二、网络编程
    C++的vector使用优化
    【kubernetes】关于云原生之k8s集群中pod的容器资源限制和三种探针
    asp.net课程设计旅游景点推荐系统网站
    使用 Postman 工具高效管理和测试 SAP ABAP OData 服务的试读版
    NetCore路由的Endpoint模式
  • 原文地址:https://blog.csdn.net/qq_38220914/article/details/127608591