我正在使用一个项目,通过短信向朋友发送firebase动态链接邀请。当我发送较小的链接作为邀请时,我的代码运行完全正常并发送短信。像
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();
}
但是当我包含超过一个sms字符限制的更大链接时它不会发送短信,尽管它显示了吐司通知。
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 :(得分:8)
此代码可能对您有所帮助:
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();
}