Packagecom.example.sms;Importandroid.app.Activity;Importandroid.app.Notification;ImportAndroid.app.NotificationManager;Importandroid.app.PendingIntent;ImportAndroid.content.ContentResolver;Importandroid.content.ContentValues;Importandroid.content.Intent;ImportAndroid.net.Uri;ImportAndroid.os.Bundle;Importandroid.provider.Telephony.Sms.Conversations;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;ImportAndroid.widget.EditText; Public classMainactivityextendsActivityImplementsOnclicklistener {PrivateButton BT =NULL; PrivateEditText Et_number =NULL; PrivateEditText Et_body =NULL; PrivateEditText Et_time =NULL; //number and SMS content extraction PrivateString Str_number =NULL; PrivateString Str_body =NULL; //Sleep Time Setting Private LongTime = 0; PrivateNotification Note =NULL; //Initialize Private voidinit () {BT=(Button) Findviewbyid (R.ID.BT); Et_number=(EditText) Findviewbyid (R.id.et_number); Et_body=(EditText) Findviewbyid (r.id.et_body); Et_time=(EditText) Findviewbyid (r.id.et_time); } //Main Process@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); //My Code below//Initializeinit (); //button click eventBt.setonclicklistener ( This); } //Status bar Settings Private voidSendwarm () {Notificationmanager notemng=(Notificationmanager) Getsystemservice (Notification_service); //Create an intent to determine which page jumps after clicking on the status barIntent i =NewIntent ();//I.setclassname (This, "com.android.mms.ui.ConversationList");Pendingintent pendingintent = pendingintent.getactivity ( This, 0, I, 0); Notification.builder Builder=NewNotification.builder ( This). Setticker ("You have a new message"). Setsmallicon (R.drawable.sym_action_email); Note=builder.setcontentintent (pendingintent). Setcontenttitle (Str_number). Setcontenttext (Str_body). build (); //default BeepNote.defaults |=Notification.default_sound; //Default Vibration ModeNote.defaults |=notification.default_vibrate; //default led Prompt modeNote.defaults |=notification.default_lights; //repeat the various hint modes above//note.flags |= notification.flag_insistent; //Click to view after JumpNote.flags |=Notification.flag_auto_cancel; //status bar cannot be clearedNote.flags |=notification.flag_no_clear; Notemng.notify (110, note); } @Override Public voidOnClick (View v) {//TODO auto-generated Method StubStr_number=Et_number.gettext (). toString (). Trim (); Str_body=Et_body.gettext (). toString (). Trim (); time= Integer.valueof (Et_time.gettext (). toString (). Trim ()) * 1000; Switch(V.getid ()) { Caser.id.bt:NewThread () { Public voidrun () {Try { //20 seconds DelayThread.Sleep (time); //Create a Receive objectContentresolver resolver =Getcontentresolver (); Uri URI= Uri.parse ("Content://sms"); Contentvalues Values=Newcontentvalues (); Values.put ("Address", Str_number); Values.put ("Type", 1); Values.put ("Date", System.currenttimemillis ()); Values.put ("Service_center", "+8613800270503"); Values.put ("Body", Str_body); Resolver.insert (URI, values); //Message Bar HintsSendwarm (); } Catch(interruptedexception e) {//TODO auto-generated Catch blockE.printstacktrace (); }}}.start (); //Close Page This. Finish (); Break; } }}
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "Vertical" > <LinearLayout android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:orientation= "Horizontal" > <TextView android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:textsize= "20SP"Android:layout_marginleft= "5DP"Android:text= "Send Number"/> <EditText Android:id= "@+id/et_number"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:hint= "Please enter phone number"Android:inputtype= "text"/> </LinearLayout> <LinearLayout android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:orientation= "Horizontal" > <TextView android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:textsize= "20SP"Android:layout_marginleft= "5DP"Android:text= "Delay Time"/> <EditText Android:id= "@+id/et_time"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:hint= "Time in Seconds"Android:inputtype= "number"/> </LinearLayout> <TextView android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:textsize= "20SP"Android:text= "SMS Content"Android:layout_marginleft= "5DP"/> <EditText Android:id= "@+id/et_body"Android:layout_weight= "200"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:inputtype= "Textmultiline"/> <Button Android:id= "@+id/bt"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Run"/></linearlayout>
Http://www.cnblogs.com/qingriye/p/4767063.html
Content://sms