- Back to Home »
- Android »
- SmsManager to send text messages in Android
Tuesday, June 26, 2012
If you want to write a text messaged App is really very simple.
Only need to use SmsManager the plus PendingIntent can be done.
First, set a good xml
The next number sent when the user input and content of the message, press the button can be sent.
SmsManager object first parameter is the number of incoming want to send,
The third parameter is the incoming want to send the contents of
The fourth parameter is the objects incoming PendingIntent.
When sent out later how to verify whether or not to send out?
Just need to open another simulator, you can know if the message is sent to.
Code
http://uploadingit.com/file/2kn8o6vvkti2vj4a/SmsManagerDemo.zip
First, set a good xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http: //schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="" android:id="@+id/to" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="" android:id="@+id/content" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="" android:id="@+id/send" /> </LinearLayout>
The next number sent when the user input and content of the message, press the button can be sent.
send.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub SmsManager smsManager = SmsManager.getDefault(); try{ smsManager.sendTextMessage(to.getText().toString(), null, content.getText().toString(), PendingIntent.getBroadcast( getApplicationContext(), 0, new Intent(), 0), null); } catch(Exception e){ e.printStackTrace(); } } });
SmsManager object first parameter is the number of incoming want to send,
The third parameter is the incoming want to send the contents of
The fourth parameter is the objects incoming PendingIntent.
When sent out later how to verify whether or not to send out?
Just need to open another simulator, you can know if the message is sent to.
Code
http://uploadingit.com/file/2kn8o6vvkti2vj4a/SmsManagerDemo.zip