-1

This is my code for sending SMS from my app:

protected void send() {
    String no = mobileno.getText().toString();
    String msg = message.getText().toString();

    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(no, null, msg, null, null);
    Toast.makeText(getApplicationContext(), "sms sent", Toast.LENGTH_LONG).show();
}

my code for activity.xml is:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.spinnerex">

        <uses-permission android:name="android.permission.SEND_SMS"/>

        <uses-permission android:name="android.permission.RECEIVE_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>

It shows SMS sent but I have not received any SMS. It shows no error but the SMS is not received.

ardiien
  • 767
  • 6
  • 26
  • Does this answer your question? [Android sms manager not sending sms](https://stackoverflow.com/questions/18828455/android-sms-manager-not-sending-sms) – ardiien Mar 10 '20 at 08:38

1 Answers1

1

Did you implement permission requests for a user? You have to ask permission for using SmsManager.

how to add permission in my sms manager

ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.SEND_SMS},1);

But this way is the worst. You have to ask the user directly. You can Google it. For testing if it is the problem, you can manually grand it in settings -> your app setting -> app permission.

As an option, you may use this as the reference.

In addition, might be helpful as well Android sms manager not sending sms

ardiien
  • 767
  • 6
  • 26