zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    自定义组件
    vue 父子组件传值数据不能实时更新问题
    vuex(2)
    vuex(1)
    mysql-忘记密码
    转发&重定向
    mysql主从配置
    mysql安装脚本
    1、JAVA数据类型
    maven 国内阿里云镜像配置
  • 原文地址:https://www.cnblogs.com/fengzikuange/p/6183139.html
Copyright © 2011-2022 走看看