当前位置: 代码迷 >> Android >> Android - 零星记录[短信发送,系统拨号,单元测试]
  详细解决方案

Android - 零星记录[短信发送,系统拨号,单元测试]

热度:277   发布时间:2016-05-01 13:34:50.0
Android -- 零散记录[短信发送,系统拨号,单元测试]
1.调用系统的拨号:

Intent inttent=new Intent(Intent.ACTION_CALL,Uri.pars("tel:"+mobile));


2.系统自带的短信发送:
配置权限:



String mobile = mobileText.getText().toString();String content = contentText.getText().toString();SmsManager smsManager = SmsManager.getDefault();if (content.length() > 70) {	List<String> contents = smsManager.divideMessage(content);	for (String smsStr : contents) {		smsManager.sendTextMessage(mobile, null, smsStr, null, null);	}}else {	smsManager.sendTextMessage(mobile, null, content, null, null);}Toast.makeText(SmsActivity.this, "短信发送成功!", Toast.LENGTH_LONG).show();


3.单元测试:
(1),单元测试三与单元测试四的区别
单元测试三  方法必须以test开头;
单元测试四  [email protected]
(2),android里面的单元测试
mainfest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"      package="org.hs"      android:versionCode="1"      android:versionName="1.0">    <uses-sdk android:minSdkVersion="4" />    <application android:icon="@drawable/icon" android:label="@string/app_name">    	<uses-library android:name="android.test.runner" ></uses-library>        <activity android:name=".Activity02"                  android:label="@string/app_name">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>		<activity android:name=".OtherActivity" android:label="@string/other">		</activity>    </application>    <instrumentation android:name="android.instrumentationTestRunner" android:targetPackage="org.hs" android:label="android Test" ></instrumentation></manifest>

LogTest.java
package org.hs;import android.test.AndroidTestCase;import android.util.Log;public class LogTest extends AndroidTestCase {		private static final String TAG="LogTest";//shift+crtl+s  小写变大写		public void testOne() throws Exception{		int i=1+1;		Log.i(TAG, "result="+i);	}}
  相关解决方案