• android 调用电话功能


    今天用到了打电话的功能,这要如何实现呢?

    很简单

    1.创建对应对的xml展示页面喝java文件

    2.在manifest中添加权限

    下面上代码吧:

    这是布局的一部分

    <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <Button
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="电话:123456789001"
                    android:id="@+id/more_phone"
                    android:background="#ff6666"
                    android:textSize="20dp"/>
    
            </LinearLayout>
    

    在对应对的java代码绑定好控件以后下面就是正餐了:

    在监听方法中使用

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

    这个语句就可以调用打电话的功能了。

     public void onClick(View view) {
    
                switch (view.getId()){
    
                    case R.id.more_phone:
    
                        String phone_number = phone.getText().toString();
                        Intent  intent = new Intent(Intent.ACTION_CALL , Uri.parse("tel:"+phone_number));
                        startActivity(intent);
                        break;
    

     当然还需要加一下权限:

    在androidmainfest.xml中添加

    <!-- 打电话 -->
        <uses-permission android:name="android.permission.CALL_PHONE"/>
    

     这句就是大电话的权限了

    转自我的个人博客:http://121.42.143.160/wordpress

  • 相关阅读:
    python中实现mysql连接池
    flask简单的路由分发
    用进程池创建子进程
    用类创建子进程
    用函数创建子进程
    fiddler抓包工具使用
    requests库的小技巧
    requests库的get请求,带有cookies
    requests库的post请求
    Android下Json数据解析
  • 原文地址:https://www.cnblogs.com/wobeinianqing/p/5050950.html
Copyright © 2020-2023  润新知