2016-07-20 59 views
-1

我有一些代碼從我的應用程序發送短信但是這個代碼只能發送160個字符,並不能發送超過160多這是我的代碼:如何在Android中發送超過160個字符的短信?

protected void sendMessage(String message){ 

     String phoneNumber = "xxxx"; 

     try { 

      if(message.length() < 161){ 
       SmsManager smsManager = SmsManager.getDefault(); 
       smsManager.sendTextMessage(phoneNumber, null, message, null, null); 

       Toast.makeText(getApplicationContext(), "SMS Send !", Toast.LENGTH_LONG).show(); 
      }else{ 
       Toast.makeText(getApplicationContext(), "Character too long !", Toast.LENGTH_LONG).show(); 
      } 

     }catch (Exception e){ 
      Toast.makeText(getApplicationContext(), "SMS Failed !", Toast.LENGTH_LONG).show(); 
      e.printStackTrace(); 
     } 

    } 

如何與超過160個字符發送短信?

回答

0

通過2條短信發送消息。短信有160的限制。

2

發送像這樣,而不用擔心它的大小。

protected void sendMessage(String message) { 
     try { 
      String phoneNumber = "xxxx"; 
      SmsManager smsManager = SmsManager.getDefault(); 

      ArrayList<String> parts = smsManager.divideMessage(message); 
      //smsManager.sendTextMessage(phoneNumber, null, message, null, null); 
      smsManager.sendMultipartTextMessage(phoneNumber, null, parts, 
        null, null); 
      Toast.makeText(getApplicationContext(), "SMS Send !", Toast.LENGTH_LONG).show(); 
     } catch (Exception e) { 
      Toast.makeText(getApplicationContext(), "SMS Failed !", Toast.LENGTH_LONG).show(); 
      e.printStackTrace(); 
     } 
    }