• android 实现拨号功能,让用户选择是否拨号,不自动拨号


    activity_main.xml

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     android:id="@+id/activity_main"
     4     android:layout_width="match_parent"
     5     android:layout_height="match_parent"
     6     android:orientation="vertical">
     7     <EditText
     8         android:id="@+id/phone"
     9         android:layout_width="match_parent"
    10         android:layout_height="25dp"
    11         android:hint="请输入手机号" />
    12     <Button
    13         android:id="@+id/cal"
    14         android:layout_width="match_parent"
    15         android:layout_height="wrap_content"
    16         android:onClick="onClick"
    17         android:text="拨号"/>
    18 </LinearLayout>

    MainActivity.java

     1 package com.example.teletephone;
     2 import android.content.Intent;
     3 import android.net.Uri;
     4 import android.support.v7.app.AppCompatActivity;
     5 import android.os.Bundle;
     6 import android.view.View;
     7 import android.widget.EditText;
     8 public class MainActivity extends AppCompatActivity  implements View.OnClickListener{
     9     private EditText phone;
    10     @Override
    11     protected void onCreate(Bundle savedInstanceState) {
    12         super.onCreate(savedInstanceState);
    13         setContentView(R.layout.activity_main);
    14         phone= (EditText) findViewById(R.id.phone);
    15     }
    16     @Override
    17     public void onClick(View v) {
    18         switch (v.getId()){
    19             case R.id.cal:
    20                 Intent intent = new Intent(Intent.ACTION_DIAL);
    21                 intent.setData(Uri.parse("tel:"+phone.getText()));
    22                 startActivity(intent);//内部类
    23                 break;
    24         }
    25     }
    26 }
  • 相关阅读:
    springboot springdata 整合es
    forkJoinPool
    springboot整合ElasticSearch
    雪花算法生成全局唯一ID
    linux环境下elasticsearch+kibana+ik(实现热词自动更新)
    ECMAScript 6新特性简记
    Tsung:开源多协议分布式负载&压力测试工具
    js 数组迭代方法总结
    js for循环
    箭头函数this的问题
  • 原文地址:https://www.cnblogs.com/fengzikuange/p/6183139.html
Copyright © 2020-2023  润新知