Joke Collection Website - Public benefit messages - Android has developed a method to automatically send short messages to designated numbers through server content.
Android has developed a method to automatically send short messages to designated numbers through server content.
Similar to the interface below.
activity_main.xml
[html] view plain text
& ltrelative layout xmlns:Android = "/apk/RES/Android "?
xmlns:tools="/tools "?
Android:layout _ width = " match _ parent "?
Android:layout _ height = " match _ parent " & gt; ?
& lt button?
android:id="@+id/btn_send "?
Android:layout _ width = " wrap _ content "?
Android:layout _ height = " wrap _ content "?
Android:layout _ alignParentRight = " true "?
Android:layout _ margin right = " @ dimen/padding _ small "?
Android: Gravity = "center"?
Android:padding left = " @ dimen/padding _ small "?
Android:padding right = " @ dimen/padding _ small "?
Android:text = " @ string/BTN _ send "/& gt; ?
& ltEditText?
Android:id = " @+id/edit _ phone _ number "?
Android:layout _ width = " fill _ parent "?
Android:layout _ height = " wrap _ content "?
Android:layout _ align bottom = " @ id/BTN _ send "?
Android:layout _ margin left = " @ dimen/padding _ small "?
Android:layout _ margin right = " @ dimen/padding _ small "?
Android:layout _ toLeftOf = " @ id/BTN _ send "?
Android:hint = " @ string/edittext _ hint "?
android:inputType="phone "?
Android:padding left = " @ dimen/padding _ small "/& gt; ?
& lt/relative layout & gt; ?
Then write the corresponding Java code in MainActivity. The operation is simple. Enter the number in EditText, then click Send to jump to the system to send a short message, and fill in the number in the recipient column. The relevant codes are as follows:
Gets the control that responds to the click event of the button:
[java] View Plain Text
@ Overwrite?
public void onCreate(Bundle savedInstanceState){?
super . oncreate(savedInstanceState); ?
setContentView(r . layout . activity _ main); ?
medit text =(EditText)findViewById(r . id . edit _ phone _ number); ?
mButton =(Button)findViewById(r . id . BTN _ send); ?
MButton.setOnClickListener (new view. OnClickListener() {?
@ Overwrite?
Public void onClick (view v) {?
string phone number = medit text . gettext()。 toString(); ?
If (! textutils . isempty(phone number)){?
sendSmsWithNumber(main activity . this,phone number); ?
} ?
} ?
}); ?
} ?
Send SMS to the specified number:
[java] View Plain Text
/**?
* Call the system interface and send SMS to the specified number?
* ?
* @param context?
* @param number?
*/ ?
Public void sendsmswithnumber (context, string number) {?
Intent sendintention = new intention (intention. ACTION_SENDTO,uri . parse(" smsto:"+number)); ?
context . start activity(send intent); ?
} ?
After clicking Send, it will jump to the SMS interface of the system, and the recipient column is the number you just filled in.
In the same way, if you want to call the system to send SMS interface and attach the SMS content similar to the above, you only need to attach the relevant parameters in Intent.
[java] View Plain Text
/**?
* Call the system interface to send a short message with short message content to the specified number?
* ?
* @param context?
* @param number?
* @param body?
*/ ?
Public void send smswithbody (context, string number, string body) {?
Intent sendintention = new intention (intention. ACTION _ send to); ?
send intent . setdata(uri . parse(" smsto:"+number)); ?
sendIntent.putExtra("sms_body ",body); ?
context . start activity(send intent); ?
} ?
- Related articles
- What should I do if the old cadres visit the unit because of the treatment?
- What are the classic lines of Minions 3 and Minions 3?
- Happy birthday to others.
- Can China Merchants Credit Card be notified by SMS?
- What about Chengdu Ruitong Optoelectronic Technology Co., Ltd.?
- How to block the phone when moving?
- Introduction to the inquiry method of how to inquire about the bank.
- Ask a master for help.
- Complaint telephone number of Shenzhen Education Bureau
- How does telecom open roaming in Hong Kong and Macao?