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

.自动可以拨打电话

 

 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"

    />

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
[DllImport("phone.dll")] private static extern IntPtr PhoneMakeCall(ref PhoneMakeCallInfo ppmci); /// /// Dials the specified phone number. /// /// Phone number to dial. public static void MakeCall(string PhoneNumber) { MakeCall(PhoneNumber, false); } /// /// Dials the specified phone number. /// /// Phone number to dial. /// Prompts the user before the call is placed. unsafe public static void MakeCall(string PhoneNumber, bool PromptBeforeCall) { IntPtr res; PhoneNumber += '\0'; char[] cPhoneNumber = PhoneNumber.ToCharArray(); fixed (char* pAddr = cPhoneNumber) { PhoneMakeCallInfo info = new PhoneMakeCallInfo(); info.cbSize = (IntPtr)Marshal.SizeOf(info); info.pszDestAddress = (IntPtr)pAddr; if (PromptBeforeCall) { info.dwFlags = (IntPtr)PMCF_PROMPTBEFORECALLING; } else { info.dwFlags = (IntPtr)PMCF_DEFAULT; } res = PhoneMakeCall(ref info); } } } /// /// Reads information from the Subscriber Identity Module (SIM) /// public class Sim { private static long SERVICE_PROVIDER = 0x00006F46; [StructLayout(LayoutKind.Sequential)] private struct SimRecord { public IntPtr cbSize; public IntPtr dwParams; public IntPtr dwRecordType; public IntPtr dwItemCount; public IntPtr dwSize; } [DllImport("sms.dll")] private static extern IntPtr SmsGetPhoneNumber(IntPtr psmsaAddress); [DllImport("cellcore.dll")] private static extern IntPtr SimInitialize(IntPtr dwFlags, IntPtr lpfnCallBack, IntPtr dwParam, out IntPtr lphSim); [DllImport("cellcore.dll")] private static extern IntPtr SimGetRecordInfo(IntPtr hSim, IntPtr dwAddress, ref SimRecord lpSimRecordInfo); [DllImport("cellcore.dll")] private static extern IntPtr SimReadRecord(IntPtr hSim, IntPtr dwAddress, IntPtr dwRecordType, IntPtr dwIndex, byte[] lpData, IntPtr dwBufferSize, ref IntPtr lpdwBytesRead); [DllImport("cellcore.dll")] private static extern IntPtr SimDeinitialize(IntPtr hSim); /// /// Gets the phone number from the SIM. /// /// PhoneAddress structure with phone number. unsafe public static PhoneAddress GetPhoneNumber() { PhoneAddress phoneaddr = new PhoneAddress(); Byte[] buffer = new Byte[516]; fixed (byte* pAddr = buffer) { IntPtr res = SmsGetPhoneNumber((IntPtr)pAddr); if (res != IntPtr.Zero) throw new Exception("Could not get phone number from SIM"); byte* pCurrent = pAddr; phoneaddr.AddressType = (AddressType)Marshal.ReadInt32((IntPtr)pCurrent); pCurrent += Marshal.SizeOf(phoneaddr.AddressType); phoneaddr.Address = Marshal.PtrToStringUni((IntPtr)pCurrent); } return phoneaddr; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值