zoukankan      html  css  js  c++  java
  • Android实现打电话功能


    初学安卓,入门的应用 。打电话。


    新建Android 项目



    layout 控件布局 :activity_main.xml


    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >

        <TextView
            android:id="@+id/phoneview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lable_phone" />

        <EditText
            android:id="@+id/editview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/phoneview"
            android:layout_below="@+id/phoneview"
            android:layout_marginTop="14dp"
            android:ems="10"
            android:inputType="phone" >

            <requestFocus />
        </EditText>

        <Button
            android:id="@+id/butphone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/editview"
            android:layout_below="@+id/editview"
            android:layout_marginTop="16dp"
            android:text="@string/butphone" />

    </RelativeLayout>


    在AndroidManifest.xml 文件 中为其添加 打电话的 权限



      

    你会在你发现在AndroidManifest.xml 文件 中有了一断这样的代码 其为打电话的 权限

    //设置拨打电话 的权限
        <uses-permission android:name="android.permission.CALL_PHONE"/>
        <uses-permission />


    上面已经布局好 了。下面

    然后在 MainActivity  中实现其功能:


    public class MainActivity extends Activity {
    private EditText editText;
    private Button button_phone;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // 设置显示pylt
    setContentView(R.layout.activity_main);

    //获取按钮组件
    button_phone=(Button) findViewById(R.id.butphone);
    //获取输入框组件
    editText = (EditText) findViewById(R.id.editview);

    //注册按钮事件
    button_phone.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub
    //获取号码
    String phone_Num = editText.getText().toString();

    //定义执行打电话的意图对象
    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+phone_Num));

    //执行意图
    MainActivity.this.startActivity(intent);

    //吐司的效果
    Toast.makeText(MainActivity.this, "正在给"+phone_Num+"打电话",Toast.LENGTH_LONG).show();

    }
    });


    }

    }


    然后把你写好的项目 发布到你的虚拟机上,Ok .








  • 相关阅读:
    nginx缓存实战
    单机编排之Docker Compose
    NGINX镜像的制作
    k8s的kube-proxy
    k8s应用环境
    k8s ansible部署部署文档
    部署docker镜像仓库及高可用
    openstack高可用集群20-openstack计算节点宕机迁移方案
    openstack 租户控制台修改虚拟机账户密码
    如何修改openstack虚拟机密码
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3109053.html
Copyright © 2011-2022 走看看