自动拨打电话,自动发送短信,测试类

时间:2022-11-10 13:48:17

.自动可以拨打电话

 

 bt.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View view) {

                EditText et = (EditText)findViewById(R.id.et);

                String number = et.getText().toString();

                //激活可以打电话的组件

                Intent intent = new Intent();

                intent.setAction("android.intent.action.CALL");

                //intent.addCategory("android.intent.category.DEFAULT");

                intent.setData(Uri.parse("tel:"+ number));

                startActivity(intent);//方法内部自动添加android.intent.category.DEFAULT

            }

        });

    }

 

.自动发送短信

 

 bt.setOnClickListener(new View.OnClickListener() {

            @Override

            public void onClick(View view) {

                    String number = numberText.getText().toString();

                    String contect = contextText.getText().toString();

                    SmsManager manager = SmsManager.getDefault();

                    //短信拆分

                    ArrayList<String> arrayList = manager.divideMessage(contect);

                    for (String text : arrayList) {

                        //第四个:是否发送 第五个:是否接受(需要移动网络产生电信号)

                        manager.sendTextMessage(number, null, text, null, null);

                    }

                    Toast.makeText(MainActivity.this, "发送成功", Toast.LENGTH_SHORT).show();

                }

            }

        });

 

.单元测试

1.

//引入单元测试的依赖库(</application>内)

        <uses-library android:name="android.test.runner"/>

 

//配置单元测试的启动装置(</application>外)

    <instrumentation

        android:name="android.test.InstrumentationTestRunner"

        android:targetPackage="com.example.lenovo.school"  //当前包名

        android:label="Tests for My App"

    />