WEB开发网
开发学院手机开发Android 开发 Android用Intent实现一个简单的短信程序 阅读

Android用Intent实现一个简单的短信程序

 2010-08-20 02:09:00 来源:WEB开发网   
核心提示:import android.app.Activity;import android.app.PendingIntent;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widg

import android.app.Activity;

import android.app.PendingIntent;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

import android.telephony.*;

import android.telephony.gsm.SmsManager;

public class TinySMS extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

final Button button=(Button)findViewById(R.id.btnsendMessage);

final EditText txtphoneNo=(EditText)findViewById(R.id.txtphoneNo);

final EditText txtMessage=(EditText)findViewById(R.id.txtMessage);

button.setOnClickListener(new View.OnClickListener(){

public void onClick(View v) {

// TODO Auto-generated method stub

String phoneNo=txtphoneNo.getText().toString();

String message=txtMessage.getText().toString();

if(phoneNo.length()>0&&message.length()>0){

sendSMS(phoneNo,message);

}

else

{

Toast.makeText(TinySMS.this, "请重新输入电话号码和短信内容",Toast.LENGTH_LONG).show();

}

}

private void sendSMS(String phoneNo, String message) {

// TODO Auto-generated method stub

//Intent intent=new Intent();

//intent.setClass(TinySMS.this,TinySMS.class);

PendingIntent pi=PendingIntent.getActivity(TinySMS.this, 0, new Intent(TinySMS.this,TinySMS.class), 0);

SmsManager sms=SmsManager.getDefault();

sms.sendTextMessage(phoneNo, null,message, pi, null);

}

});

}

}

可以参考一下网址做更详细的了解:

http://www.cnblogs.com/xirihanlin/archive/2009/10/18/1585624.html

Tags:Android Intent 实现

编辑录入:coldstar [复制链接] [打 印]
赞助商链接