I'm trying to make an application that sends an SMS message. I found many articles and questions on stackoverflow, but still the application does not send sms, and there are no messages in logcat at all. Please specify all the necessary actions to send a message directly from the application (without calling a third-party).

What has been done (using the code from this tutorial).

In the manifest:

<?xml version="1.0" encoding="utf-8"?> 

 <uses-permission android:name="android.permission.SEND_SMS"/> <uses-feature android:name="android.hardware.telephony" android:required="true"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.shinobicontrols.messageme.ConversationListActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.shinobicontrols.messageme.ConversationDetailActivity" android:label="@string/title_conversation_detail" android:parentActivityName="com.shinobicontrols.messageme.ConversationListActivity" > <meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.shinobicontrols.messageme.ConversationListActivity" /> </activity> <!-- BroadcastReceiver that listens to incoming SMS messages --> <receiver android:name="com.shinobicontrols.messageme.receivers.SMSBroadcastReceiver" android:permission="android.permission.BROADCAST_SMS" > <intent-filter> <action android:name="android.provider.Telephony.SMS_DELIVER" /> </intent-filter> </receiver> <!-- BroadcastReceiver that listens to incoming MMS messages --> <receiver android:name="com.shinobicontrols.messageme.receivers.MMSBroadcastReceiver" android:permission="android.permission.BROADCAST_WAP_PUSH" > <intent-filter> <action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" /> <data android:mimeType="application/vnd.wap.mms-message" /> </intent-filter> </receiver> <!-- Activity for composing SMS/MMS messages --> <activity android:name="com.shinobicontrols.messageme.ComposeSMSActivity" android:label="@string/title_activity_compose_sms" > <intent-filter> <action android:name="android.intent.action.SEND" /> <action android:name="android.intent.action.SENDTO" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="sms" /> <data android:scheme="smsto" /> <data android:scheme="mms" /> <data android:scheme="mmsto" /> </intent-filter> </activity> <!-- Service that delivers messages for "Quick Response" --> <service android:name="com.shinobicontrols.messageme.HeadlessSmsSendService" android:exported="true" android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE" > <intent-filter> <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="sms" /> <data android:scheme="smsto" /> <data android:scheme="mms" /> <data android:scheme="mmsto" /> </intent-filter> </service> </application> 

Code for the button to send a message:

 public void onClick(View v) { String recipient = ((TextView)rootView.findViewById(R.id.composeEditTextTo)).getText().toString(); String message = ((TextView)rootView.findViewById(R.id.composeEditTextMessage)).getText().toString(); SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(recipient, null, message, null, null); } 

In the settings I chose it as a default SMS application.

Phone ASUS Zenfone Laser (ASUS_Z00RD), Android 5.0.2, API 21. Dual sim, but there is only one SIM card. Money to send enough.

  • Try to catch for example through Toast more information. Very interesting behavior of the block with smsManager . And it would be nice to try catch wrap it in try catch . - Serodv
  • @Serodv and what exactly to display and how to get information? I have very little experience in android sdk. - Vladimir Mikhailov
  • try{ SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(recipient, null, message, null, null); } catch(Exception e) { Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } try{ SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(recipient, null, message, null, null); } catch(Exception e) { Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } - Serodv
  • @Serodv no mistakes happen here - Vladimir Mikhailov
  • So the dog rummaged somewhere before - Serodv

1 answer 1

The error was to enter the phone number. The phone number must be written not through "+7", but through "8." However, it is strange that I did not receive a message about the incorrectness of the number (which occurred at least in the case of an empty string instead of a number), it is possible that the "+" is erased. I hope that a person in Marshall Islands will forgive me three days of spamming with the word "test" :)

  • The human factor, as usual - Serodv