Sending an SMS (not just creating the text and requiring the user to hit send) can't be that difficult, and yet I've spent the past eleven hours reading every stackoverflow entry and failing nonetheless. I'm now wondering if maybe the method has changed recently since none of the examples seem to work. If someone could help me with this, I'd be grateful. This is my first post, so my apologies if I'm not following the conventions of the community.
Here is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="joe.sms">
<uses-permission android:name="android.permission.SEND_SMS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And here is my MainActivity:
package.joe.sms;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("+1716255xxxx", null, "Test message", null, null);
}
}
Note: I use my full phone number in the actual code.
And here is the result:
Thanks, in advance, for your assistance.