sendTextMessage In android phone

后端 未结 4 2024
温柔的废话
温柔的废话 2020-12-06 23:40

This is simple code send SMS.

47: SmsManager sms = SmsManager.getDefault();
48: sms.sendTextMessage(\"12345678901\", null, \"hello!\", null, null);


        
相关标签:
4条回答
  • 2020-12-07 00:10

    This Problem also Occurs when your msg length exceeds normal text msg length(i.e 160 Character) you need to divide the msg into parts and send... Use this code it may help you

    public static void sendSms(Activity curActivity, String phoneNumber, String msg) {
     SmsManager smsManager = SmsManager.getDefault(); 
    
     ArrayList<String> msgStringArray = smsManager.divideMessage(msg);      
    
     smsManager.sendMultipartTextMessage(phoneNumber, null, msgStringArray, null, null);
    }
    
    0 讨论(0)
  • 2020-12-07 00:13

    give the pending intent in your 48th line as given bellow

    String sent = "android.telephony.SmsManager.STATUS_ON_ICC_SENT";
    PendingIntent piSent = PendingIntent.getBroadcast(smsActivity.this, 0,new Intent(sent), 0);
    
    sms.sendTextMessage("12345678901", null, "hello!", piSent, null);
    

    am sure it works :)

    0 讨论(0)
  • 2020-12-07 00:24

    The Null Exception is in the SMS lenght, you may use

    try {}catch(Exception ex) {}
    

    in your code in case you get null exception and try send "divided" sms using:

    ArrayList<String> parts = sms.divideMessage(message);
    sms.sendMultipartTextMessage(telephone, null, parts, null, null);
    
    0 讨论(0)
  • 2020-12-07 00:28

    I had this problem when using special characters in the SMS Message. Changing to normal english characters worked for me.

    0 讨论(0)
提交回复
热议问题