• 自写-自动拨号测试app


    XML - Main

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.example.prize.mydemo.MainActivity"
        tools:layout_editor_absoluteY="81dp"
        tools:layout_editor_absoluteX="0dp">
    
       <Button
           android:id="@+id/button1"
           android:text="写入号码"
           android:layout_width="0dp"
           android:layout_height="48dp"
           tools:layout_constraintTop_creator="1"
           tools:layout_constraintRight_creator="1"
           android:layout_marginStart="25dp"
           android:layout_marginEnd="25dp"
           app:layout_constraintRight_toRightOf="parent"
           android:layout_marginTop="97dp"
           tools:layout_constraintLeft_creator="1"
           app:layout_constraintLeft_toLeftOf="parent"
           app:layout_constraintTop_toTopOf="parent" />
        <Button
            android:id="@+id/button2"
            android:text="写入次数"
            android:layout_width="0dp"
            android:layout_height="48dp"
            tools:layout_constraintRight_creator="1"
            tools:layout_constraintBottom_creator="1"
            app:layout_constraintBottom_toTopOf="@+id/button4"
            android:layout_marginStart="25dp"
            android:layout_marginEnd="25dp"
            app:layout_constraintRight_toRightOf="parent"
            tools:layout_constraintLeft_creator="1"
            android:layout_marginBottom="60dp"
            app:layout_constraintLeft_toLeftOf="parent" />
    
        <Button
            android:id="@+id/buuton3"
            android:layout_width="0dp"
            android:text="清除全部"
            android:layout_height="48dp"
            android:layout_marginStart="25dp"
            tools:layout_constraintTop_creator="1"
            tools:layout_constraintRight_creator="1"
            tools:layout_constraintBottom_creator="1"
            app:layout_constraintBottom_toBottomOf="@+id/button4"
            android:layout_marginEnd="25dp"
            app:layout_constraintRight_toRightOf="parent"
            android:layout_marginTop="25dp"
            tools:layout_constraintLeft_creator="1"
            android:layout_marginBottom="60dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="@+id/button2"
            app:layout_constraintVertical_bias="1.0"
            app:layout_constraintHorizontal_bias="0.509" />
        <Button
            android:id="@+id/button4"
            android:layout_width="0dp"
            android:text="执行测试"
            android:layout_height="48dp"
            tools:layout_constraintRight_creator="1"
            tools:layout_constraintBottom_creator="1"
            android:layout_marginStart="25dp"
            app:layout_constraintBottom_toBottomOf="parent"
            android:layout_marginEnd="25dp"
            app:layout_constraintRight_toRightOf="parent"
            tools:layout_constraintLeft_creator="1"
            android:layout_marginBottom="139dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintHorizontal_bias="0.68" />
        <EditText
            android:id="@+id/text1"
            android:layout_width="0dp"
            android:layout_height="60dp"
            android:layout_marginStart="25dp"
            tools:layout_constraintTop_creator="1"
            tools:layout_constraintRight_creator="1"
            tools:layout_constraintBottom_creator="1"
            app:layout_constraintBottom_toBottomOf="@+id/button1"
            android:layout_marginEnd="25dp"
            app:layout_constraintRight_toRightOf="parent"
            android:layout_marginTop="37dp"
            tools:layout_constraintLeft_creator="1"
            android:layout_marginBottom="48dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0" />
        <EditText
            android:id="@+id/text2"
            android:layout_width="0dp"
            android:layout_height="60dp"
            android:layout_marginEnd="25dp"
            android:layout_marginStart="25dp"
            tools:layout_constraintTop_creator="1"
            tools:layout_constraintRight_creator="1"
            tools:layout_constraintBottom_creator="1"
            app:layout_constraintBottom_toBottomOf="@+id/button2"
            app:layout_constraintRight_toRightOf="parent"
            android:layout_marginTop="58dp"
            tools:layout_constraintLeft_creator="1"
            android:layout_marginBottom="55dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="@+id/button1" />
         <TextView
             android:id="@+id/text3"
             android:text=" 暗淡"
             android:layout_width="47dp"
             android:layout_height="27dp"
             tools:layout_constraintBottom_creator="1"
             android:layout_marginStart="16dp"
             app:layout_constraintBottom_toBottomOf="parent"
             tools:layout_constraintLeft_creator="1"
             android:layout_marginBottom="-5dp"
             app:layout_constraintLeft_toLeftOf="parent"
             android:layout_marginLeft="16dp" />
    </android.support.constraint.ConstraintLayout>
    

    Main的class

    package com.example.prize.mydemo;
    
    import android.content.Intent;
    import android.net.Uri;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    
    public class MainActivity extends AppCompatActivity {
        public static String [] PhoneAndTime = new String[2];
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            //初始化界面
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
    
            // 写入号码
            //find按键
            Button SetPhone = (Button)findViewById(R.id.button1);
            //创建按键监听
            SetPhone.setOnClickListener(new View.OnClickListener(){
    
                @Override
                public void onClick(View view) {
                    //获取EditText
                    EditText phoneText = (EditText)findViewById(R.id.text1);
                    PhoneAndTime[0] = String.valueOf(phoneText.getText());
                    Log.e("Demo1","号码是:"+PhoneAndTime[0]);
                    Log.e("Demo1","点击写入号码");
    
                }
            });
    
            // 重新写入号码
            /*
            Button ClearPhone = (Button)findViewById(R.id.button2);
            ClearPhone.setOnClickListener(new View.OnClickListener(){
    
                @Override
                public void onClick(View view) {
                    EditText PhoneText = (EditText)findViewById(R.id.text2);
                    PhoneText.setText("");
                    PhoneAndTime[1] = String.valueOf(PhoneText.getText());
    
                    Log.e("Demo1","点击重新写入号码");
    
                }
            });
            */
    
            //写入次数
    
            Button SetTime = (Button)findViewById(R.id.button2);
            SetTime.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    EditText timetext = (EditText)findViewById(R.id.text2) ;
                    PhoneAndTime [1] = timetext.getText().toString();
                    Log.e("Demo1","写入次数是:"+PhoneAndTime[1]);
                    Log.e("Demo1","点击写入次数");
    
                }
            });
    
    
            //重新写入
            Button ClearTime = (Button)findViewById(R.id.buuton3);
            ClearTime.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    EditText phoneText = (EditText)findViewById(R.id.text1);
                    EditText timetext = (EditText)findViewById(R.id.text2) ;
                    phoneText.setText("");
                    timetext.setText("");
                    PhoneAndTime[0] = "";
                    PhoneAndTime[1] = "";
    
                    Log.e("Demo1","点击重新写入");
                }
            });
    
            //执行测试
            Button Run = (Button)findViewById(R.id.button4);
            Run.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    //new 新的Intent
                    Intent data = new Intent(MainActivity.this,Demo_1.class);
                    //用Bundle 携带数组
                    Bundle bundle = new Bundle();
                    bundle.putStringArray("phone_data",PhoneAndTime);
                    //将 data Intent 添加Bundle
                    data.putExtras(bundle);
                    startActivity(data);
                    Log.e("Demo1","点击执行测试");
    
                }
            });
        }
    }
    执行拨号的后台 XML

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.example.prize.mydemo.Demo_1">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="拨号"
    
             />
    
    </android.support.constraint.ConstraintLayout>
    

    执行拨号的后台 class
    package com.example.prize.mydemo;
    
    import android.content.Intent;
    import android.content.IntentSender;
    import android.net.Uri;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.Toast;
    
    public class Demo_1 extends AppCompatActivity {
    
        @Override
        protected void onResume() {
            super.onResume();
            Intent intentdata = getIntent();
            Bundle bundle = this.getIntent().getExtras();
            String [] data = bundle.getStringArray("phone_data");
            Intent intent2 = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+data[0]));
            Log.e("Demo1","正在拨号");
            int time = Integer.parseInt(data[1]);
            for(int i=0;i<time;i++) {
                try {
                    startActivity(intent2);
                    Toast.makeText(Demo_1.this,"这是第:"+i+"拨号",Toast.LENGTH_SHORT).show();
    
                } catch (Exception e) {
                    e.printStackTrace();
                    Log.e("Demo1", "异常");
                }
                try {
                    Log.e("Demo1","正在通话,等待120秒");
                    Thread.sleep(120000);
                    Log.e("Demo1","等待结束");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    Log.e("Demo1", "异常2");
                }
            }
            Log.e("Demo1","拨号循环已经跳出");
            Toast.makeText(Demo_1.this,"测试完成",Toast.LENGTH_SHORT).show();
            finish();
    
    
        }
    }
    


  • 相关阅读:
    (二十)WebGIS中图层树功能的设计和实现
    WebGIS中矢量切图的初步研究
    百度兴趣点下载工具设计和实现
    服务端常规知识详解
    Shp数据批量导入Postgresql工具的原理和设计
    浅谈C#中一种类插件系统编写的简单方法(插件间、插件宿主间本身不需要通信)
    从底层开发谈WebGIS中实现地理长度固定的可视窗口的思路和方法
    用存储过程判断某个人员在一天的行进轨迹中是否有超过指定时间的停留
    Linux启动与禁止SSH用户及IP的登录
    JVM中的垃圾回收
  • 原文地址:https://www.cnblogs.com/guanxinjing/p/9708655.html
Copyright © 2020-2023  润新知