android-smsmms
android-smsmms copied to clipboard
SMS doesn't get sent/received, but code throws no errors
I'm testing my code by sending a text to myself, and my code seems to execute error-free, but I don't get the text.
Here's what I have in MainActivity.java:
protected void sendSMSMessage(String phoneNo, String msg){
try {
Settings sendSettings = new Settings();
sendSettings.setSplitCounter(false);
Transaction sendTransaction = new Transaction(this,sendSettings);
Message mMessage = new Message(msg,phoneNo);
mMessage.setType(Message.TYPE_SMSMMS);
sendTransaction.sendNewMessage(mMessage, Transaction.NO_THREAD_ID);
Toast.makeText(
getApplicationContext(),
"SMS sent",
Toast.LENGTH_LONG
).show();
Log.v("sendSMSMessage",msg);
} catch (Exception e) {
Toast.makeText(
getApplicationContext(),
"Failed to send. Try again.",
Toast.LENGTH_LONG
).show();
e.printStackTrace();
}
}
And here's what permissions I have in AndroidManifest.xml
<uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.SEND_SMS" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <uses-permission android:name="android.permission.READ_SMS" /> <uses-permission android:name="android.permission.WRITE_SMS" />
I have same problem.
I've changed the logger of the Transaction class and saw that "message not sent after delay, no longer exists"
I found the problem for sending and receiving message you need to set your application as default messaging application on android.
@meinac How do I do that?
you should check apn infomation
I guess you have forgotten
ApnUtils.initDefaultApns(this, new ApnUtils.OnApnFinishedListener() {
@Override
public void onFinished() {
}
});
Have a look at my class https://gist.github.com/amadeu01/cd8a90f9827342df58f88a30d0905749