smsManager.sendTextMessage is not working

倾然丶 夕夏残阳落幕 提交于 2019-12-17 18:44:10

问题


I have the below event to send sms programatically. However is doens't seem to work, the toast pop up appears and there is no entry in logcat, just no message is created. I have also added the appropriate permissions to manifest file.

Any suggetsions?

 private Runnable SMSRunnable = new Runnable()
 {
     public void run()
     {      
         smsManager = SmsManager.getDefault();

        smsNumber = edittextSmsNumber.getText().toString();
        smsText = edittextSmsText.getText().toString();


        smsManager.sendTextMessage(smsNumber, smsNumber, smsNumber , null, null);

     }
 };

回答1:


Try this.

SmsManager sms = SmsManager.getDefault();
PendingIntent sentPI;
String SENT = "SMS_SENT";

sentPI = PendingIntent.getBroadcast(this, 0,new Intent(SENT), 0);

sms.sendTextMessage(phoneNumber, null, message, sentPI, null);



回答2:


Actually this is working for me:

String messageText = "...YOUR TEXT HERE...";
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage("PHONE NUMBER HERE", null, messageText, null, null);

Just to be sure, with this you will not find the message sent in your message history.




回答3:


I spent lots of time then I figured out that I could just prepend the country code. For me prepending "+91" before the phone number worked like a champ.

String phnNumber="+91"+editText.getText().toString();



回答4:


This is what works for me:

PendingIntent pi = PendingIntent.getActivity(this, 0,
        new Intent(this, Next.class), 0); 
//Next is the class to move when message sent
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("phno", null, "message", null, null);


来源:https://stackoverflow.com/questions/10752394/smsmanager-sendtextmessage-is-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!