2016-10-22 110 views
-1

我正在使用通過短信向朋友發送Firebase動態鏈接邀請的項目。我的代碼運行良好,並在發送較小的鏈接作爲邀請時發送短信。像smsManager.sendTextMessage不適用於超過一個短信字符限制的郵件

try { 
     SmsManager smsManager = SmsManager.getDefault(); 
     smsManager.sendTextMessage(number, null, "Check It Out. This one is very nice and useful https://v5uht.app.goo.gl/Zi7X", null, null); 
     Toast.makeText(getApplicationContext(), "Cheers :D :D", Toast.LENGTH_LONG).show(); 
    } 

    catch (Exception e) { 
     Toast.makeText(getApplicationContext(), "SMS faild, please try again.", Toast.LENGTH_LONG).show(); 
     e.printStackTrace(); 
    } 

但它並不在我包括超過一個短信字符的限制,雖然它顯示的Toast通知更大的鏈接發送短信。

String myNewLink = "https://v5uht.app.goo.gl/?link=http://expensecount.com/&apn=com.chtl.ribath.fdynamic1&amv=1&afl=https://play.google.com/store/apps/details?id%3Dcom.belief.colorgalaxy&myPage=2"; 
    try { 
     SmsManager smsManager = SmsManager.getDefault(); 
     smsManager.sendTextMessage(number, null, myNewLink, null, null); 
     Toast.makeText(getApplicationContext(), "Cheers :D :D", Toast.LENGTH_LONG).show(); 
    } 

    catch (Exception e) { 
     Toast.makeText(getApplicationContext(), "SMS faild, please try again.", Toast.LENGTH_LONG).show(); 
     e.printStackTrace(); 
    } 

我該怎麼做才能包含myNewLink中的整個鏈接並使其工作。謝謝。

+0

,如果你需要我搜索了一些例子,但一無所獲......任何代碼:) –

+0

你必須把它在parts.Tell我,如果你PLZ分享一些代碼這將是非常有用的:D @MohammadZ –

回答

2

此代碼可以幫助你:

try { 

    SmsManager smsManager = SmsManager.getDefault(); 
    ArrayList<String> msgArray = smsManager.divideMessage(msg); 

    smsManager.sendMultipartTextMessage(phoneNo, null,msgArray, null, null); 
    Toast.makeText(getApplicationContext(), "Message Sent",Toast.LENGTH_LONG).show(); 
} catch (Exception ex) { 
    Toast.makeText(getApplicationContext(), ex.getMessage().toString(), Toast.LENGTH_LONG).show(); 
    ex.printStackTrace(); 
} 
+0

謝謝你......它解決了我的問題:D –

+0

我很高興聽到....你能標記它回答?? –

+0

我試圖發送短信使用SmsManager類的sendTextMessage與Android Nougat(Nexus)上啓用的所有權限。短信沒有發送。剛剛複製了這段代碼。它現在完美。希望這可以幫助其他人:) – varun