『壹』 如何用eclipse編寫android app實現發簡訊的功能
大概的寫一下步驟給你:
1.在android工程的配置文件里加上調用系統簡訊功能的許可權:
java"><uses-permissionandroid:name="android.permission.SEND_SMS"></uses-permission>
<uses-permissionandroid:name="android.permission.READ_SMS"></uses-permission>
<uses-permissionandroid:name="android.permission.RECEIVE_SMS"></uses-permissin>
2、主要代碼片段:
{
...
privatevoidsend1(Stringphone,Stringmessage){
PendingIntentpi=PendingIntent.getActivity(this,0,newIntent(this,testSms.class),0);
SmsManagersms=SmsManager.getDefault();
sms.sendTextMessage(phone,null,message,pi,null);
}
}
參數:phone:手機號碼
message:簡訊內容
『貳』 android直接發送p編碼後的簡訊
實現過程:
1>初始化:ATZ\r
2>設置文本模式:AT+CMGF=0\r(0:p模式,1:text模式)
3>設置PDU頭:
typedef struct {
char SCA[16]; // 短消息服務中心號碼(SMSC地址)
char TPA[16]; // 目標號碼或回復號碼(TP-DA或TP-RA)
char TP_PID; // 用戶信息協議標識(TP-PID)
char TP_DCS; // 用戶信息編碼方式(TP-DCS)
char TP_SCTS[16]; // 服務時間戳字元串(TP_SCTS), 接收時用到
char TP_UD[16]; // 原始用戶信息
char index; //短消息序號,在讀取時用到
}SM_PARAM;
// SMSC地址信息段
memset(buf, 0, sizeof(buf));
nLength = strlen(pSrc->SCA); // SMSC地址字元串的長度
buf[0] = (char)((nLength & 1) == 0 ? nLength : nLength + 1) / 2 + 1; // SMSC地址信息長度
buf[1] = 0x91; // 固定: 用國際格式號碼
nDstLength = gsmBytes2String(buf, pDst, 2); // 轉換2個位元組到目標PDU串
nDstLength += gsmInvertNumbers(pSrc->SCA, &pDst[nDstLength], nLength); // 轉換SMSC到目標PDU串
// TPDU段基本參數、目標地址等
memset(buf, 0, sizeof(buf));
nLength = strlen(pSrc->TPA); // TP-DA地址字元串的長度
buf[0] = 0x11; // 是發送簡訊(TP-MTI=01),TP-VP用相對格式(TP-VPF=10)
buf[1] = 0; // TP-MR=0
buf[2] = (char)nLength; // 目標地址數字個數(TP-DA地址字元串真實長度)
buf[3] = 0x91; // 固定: 用國際格式號碼
nDstLength += gsmBytes2String(buf, &pDst[nDstLength], 4); // 轉換4個位元組到目標PDU串
nDstLength += gsmInvertNumbers(pSrc->TPA, &pDst[nDstLength], nLength); // 轉換TP-DA到目標PDU串
// TPDU段協議標識、編碼方式、用戶信息等
//nLength = strlen(pSrc->TP_UD); // 用戶信息字元串的長度
memset(buf, 0, sizeof(buf));
buf[0] = pSrc->TP_PID; // 協議標識(TP-PID)
buf[1] = pSrc->TP_DCS; // 用戶信息編碼方式(TP-DCS)
buf[2] = 1; // 有效期(TP-VP)為5分鍾
buf[3] = str2hex(user_p, pSrc->TP_UD); //用戶信息的長度
nDstLength += gsmBytes2String(buf, &pDst[nDstLength], 4); // 轉換該段數據到目標PDU串
strcat(p, "\x01a"); //以CTRL-A結束
gsmString2Bytes(p, &nSmscLength, 2); // 取PDU串中的SMSC信息長度
4>發送信息長度:AT+CMGS=長度,這步重要長度不對是發不出去的。
5>發送用戶信息
1、目前,發送短消息常用Text和PDU(Protocol Data Unit,協議數據單元)模式。
1>使用Text模式收發簡訊代碼簡單,實現起來十分容易,但最大的缺點是不能收發中文簡訊;
2>使用PDU模式不僅支持中文簡訊,也能發送英文簡訊。
2、PDU模式收發簡訊可以使用3種編碼:
1>7-bit(用於發送普通的ASCII字元,它將一串7-bit的字元(最高位為0)編碼成8-bit的數據,每8個字元可 「壓縮」成7個)
2>8-bit(通常用於發送數據消息,如:圖片了,鈴聲等等)
3>UCS2編碼(用於發送Unicode字元)
『叄』 怎麼給android 加入發送免費簡訊功能
首先,應該在程序清單文件AndroidManifest.xml中加入發簡訊的許可權
<uses-permission android:name="android.permission.SEND_SMS"/>
包括兩個TextView組件,兩個EditText組件,一個Button組件,在主程序為發送按鈕增加單擊事件
private EditText txt_num;
private EditText txt_content;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txt_num= (EditText) this.findViewById(R.id.txt_num);
txt_content=(EditText) this.findViewById(R.id.txt_content);
Button btn_send = (Button) this.findViewById(R.id.btn_send);
btn_send.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String str_num = txt_num.getText().toString();//得到電話號碼
String str_content = txt_content.getText().toString();//得到簡訊內容
SmsManager manager_sms = SmsManager.getDefault();//得到簡訊管理器
//由於簡訊可能較長,故將簡訊拆分
ArrayList<String> texts = smsManager.divideMessage(str_content);
for(String text : texts){
smsManager.sendTextMessage(str_num, null, text, null, null);//分別發送每一條簡訊
}
Toast.makeText(SMSActivity.this, "發送成功!", Toast.LENGTH_LONG).show();//提示成功
}
});
}
至此,發送簡訊功能介紹完畢
『肆』 如何給android模擬器發送簡訊
工具/原料
Eclipse開發平台
Android SDK
與Eclipse和Android SDK版本相對應的ADT
方法/步驟
啟動Eclipse,並配置Android模擬器。右鍵你的Project -->Run As -->Run Configuratios -->如下圖-->然後點擊RUN(運行)。選擇所要使用的模擬器。
打開DDMS(Dalvik Debug Monitor Service)
打開Emulator Control,進入Emulator Control界面。
在Emulator Control界面中輸入要發送簡訊的手機號碼,這里為模擬器的號碼。模擬器的號碼查看方法如圖所示。
選擇簡訊模式並編輯簡訊
接收簡訊並驗證簡訊內容
『伍』 android 發送長簡訊怎麼實現
源碼SmsManager類里有個方法可以用來發送長簡訊,代碼如下:
public void sendMultipartTextMessage(
String destinationAddress, String scAddress, ArrayList<String> parts,
ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents) {
if (TextUtils.isEmpty(destinationAddress)) {
throw new IllegalArgumentException("Invalid destinationAddress");
}
if (parts == null || parts.size() < 1) {
throw new IllegalArgumentException("Invalid message body");
}
if (parts.size() > 1) {
try {
ISms iccISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));
if (iccISms != null) {
iccISms.sendMultipartText(destinationAddress, scAddress, parts,
sentIntents, deliveryIntents);
}
} catch (RemoteException ex) {
// ignore it
}
} else {
PendingIntent sentIntent = null;
PendingIntent deliveryIntent = null;
if (sentIntents != null && sentIntents.size() > 0) {
sentIntent = sentIntents.get(0);
}
if (deliveryIntents != null && deliveryIntents.size() > 0) {
deliveryIntent = deliveryIntents.get(0);
}
sendTextMessage(destinationAddress, scAddress, parts.get(0),
sentIntent, deliveryIntent);
}
}
『陸』 android 幾種發送簡訊的方法
MQTT協議實現Android推送
.RSMB實現推送
XMPP協議實現Android推送
『柒』 如何在android中實現發送簡訊,簡訊文本顯示超鏈接
目前手機不支持超鏈接的,部分手機支持識別地址、電話、網址,但均不支持文本超鏈接!
『捌』 如何在模擬器上向android發送簡訊和撥打電話
一般是可以在網段內進行模擬的:
android在DDMS上就可以發送簡訊和撥打電話。在Eclips中運行程序,並啟動模擬器以後,我們點擊按鈕,切換到DDMS這個視圖。我們看到這邊有一個叫做Emulator Control(模擬器控制的窗口),我們看到在這個地方現在是灰色的,這是因為我們需要在Device中選中我們的模擬器,不然如果你有多個模擬器的話,DDMS就不清楚你到底要發給誰了。我們就可以在選擇voice或者SMS來向我們的模擬器撥打電話,或者發送簡訊了。Message框裡面是我們用來輸入簡訊的。Imcoming number是來電話的電話號碼。