android-smsmms icon indicating copy to clipboard operation
android-smsmms copied to clipboard

SMS doesn't get sent/received, but code throws no errors

Open DABESTAPPSEVER opened this issue 10 years ago • 6 comments

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" />

DABESTAPPSEVER avatar Feb 22 '15 18:02 DABESTAPPSEVER

I have same problem.

meinac avatar Mar 14 '15 21:03 meinac

I've changed the logger of the Transaction class and saw that "message not sent after delay, no longer exists"

meinac avatar Mar 15 '15 01:03 meinac

I found the problem for sending and receiving message you need to set your application as default messaging application on android.

meinac avatar Mar 22 '15 01:03 meinac

@meinac How do I do that?

DABESTAPPSEVER avatar Apr 08 '15 22:04 DABESTAPPSEVER

you should check apn infomation

gracefulife avatar May 05 '15 07:05 gracefulife

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

amadeu01 avatar Oct 23 '17 17:10 amadeu01