Android texting program, but no effect.

Source: Internet
Author: User

============ Problem Description ============


This code is the activity inside the layout of I do not post, I set the toast have been reported, but the text message still can not be sent out.

Package com.example.message;import android.app.activity;import android.app.pendingintent;import  android.content.intent;import android.os.bundle;import android.telephony.smsmanager;import  android.util.Log;import android.view.Menu;import android.view.View;import  Android.view.view.onclicklistener;import android.widget.button;import android.widget.edittext;import  android.widget.Toast;public class MainActivity extends Activity {public  button send;public edittext number,message; @Overrideprotected  void oncreate (Bundle  savedinstancestate)  {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); send  =  (Button) This.findviewbyid (r.id.send);number =  (EditText) This.findviewbyid (R.id.number); message =  (EditText) This.findviewbyid (r.id.msg); Send.setonclicklistener (New onclicklistener () {@ Overridepublic void onclIck (view arg0)  {// todo auto-generated method stubsendmessage ();});} Public void sendmessage () {String pnumber = number.gettext (). toString (). Trim (); String msg = message.gettext (). toString (). Trim ();   pendingintent sentintent  = pendingintent.getbroadcast (This, 0, new intent (),  0), if ("". Equals (msg) | | "". Equals (Pnumber)) {Toast.maketext (this,  "need to fill in the number, cut text message content cannot be empty",  toast.length_long). Show (); ELSE{LOG.I ("Message",  "Recipient:" +pnumber+ "   info:" +msg "); Smsmanager sms = smsmanager.getdefault (); Sms.sendtextmessage (pnumber,  "13652179825",  Msg, sentintent, null);  toast.maketext (this,  "sent successfully! ",  toast.length_long). Show ();}} @Overridepublic  boolean oncreateoptionsmenu (Menu menu)  {// inflate the menu ;  this adds items to the action bar if it is&nbsP;present.getmenuinflater (). Inflate (r.menu.main, menu); return true;}} 

I added the authority Android.permission.SEND_SMS also put other related text messages and MMS permissions are added, but log inside prompted permission denied, because my virtual machine has a problem my test using the real machine. I am very short of knowledge in Android, but also ask the gods to see what is the line?

============ Solution 1============


Sms.sendtextmessage (This is the address of the recipient, NULL, MSG, send, NULL); You try this. The second parameter is the SMS Service center phone, and you wrote it wrong. should be null

============ Solution 2============


You debug to see what happens when it executes Logcat, the second parameter is the service center,

============ Solution 3============


Your phone is not loaded with 360 of such management software, so you blocked the action of short message

Android texting program, but no effect.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.