標籤:android 發簡訊 移動端
package org.crazyit.manager;
import android.R.integer;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
public class SendSms extends Activity
{
EditText number, content,no,def;
Button send,setDefault;
SmsManager sManager;
static String SUC;
String a;
String b;
int count = 1;
int bianhao;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
sManager = SmsManager.getDefault();
number = (EditText) findViewById(R.id.number);
content = (EditText) findViewById(R.id.content);
no = (EditText)findViewById(R.id.no);
send = (Button) findViewById(R.id.send);
def = (EditText)findViewById(R.id.def);
setDefault = (Button)findViewById(R.id.sure);
//強制類型轉換 轉成String
setDefault.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(no.getText().toString().equals("")||def.getText().toString().equals("")){
Toast.makeText(SendSms.this, "請輸入預設內容",Toast.LENGTH_SHORT
).show();
return;
}
String getDef;
getDef = def.getText().toString();
a = no.getText().toString();
bianhao = Integer.parseInt(a);
content.setText(getDef +a + "號");
count = bianhao;
}
});
send.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
//判斷號碼是否為空白
if(number.getText().toString().equals(""))
{
Toast.makeText(SendSms.this, "請輸入電話號碼", Toast.LENGTH_LONG).show();
return;
}
//擷取編號
b = no.getText().toString();
//如果擷取的編號不等於count
if(!b.equals(a)){
count = Integer.parseInt(b);
//強制轉換成int型
b = String.valueOf(count);
no.setText(b);
count++;
content.setText(def.getText().toString()+b+"號");
}else
{
count++;
a = String.valueOf(count);
no.setText(a);
content.setText(def.getText().toString()+a+"號");
}
PendingIntent pi = PendingIntent.getActivity(
SendSms.this, 0, new Intent(), 0);
sManager.sendTextMessage( number.getText().toString(),
null, content.getText().toString()+no.getText().toString()+"號",
pi, null);
Toast.makeText(SendSms.this, "簡訊發送完成", 8000).show();
a = String.valueOf(count);
no.setText(a);
number.setText("");
}
});
}
}
以上是java代碼 主要功能則是快遞老師每發完一條簡訊簡訊編號加1
本文出自 “我的SendMsg” 部落格,請務必保留此出處http://9544751.blog.51cto.com/9534751/1570297
前些天給圖書館老師做的快遞發簡訊小軟體