Below is an example of how you can share or send an SMS programmatically via an Android Intent,
- Create an object on Intent object with Intent.ACTION_VIEW and Uri,
- Using putExtra provide the sms body
- Start the activity
Intent message = new Intent( Intent.ACTION_VIEW, Uri.parse( "sms:" + "" ) );
message.putExtra( "sms_body", "Put your SMS text here" );
startActivity(message);
Note: You would require to have permissions enabled to SEND SMS, this can be done by adding the below code in Manifest,
<uses-permission android:name="android.permission.SEND_SMS" />
If you want to sent an MMS you may have to use some more options,
public void sendSmsMessage(String sms, Uri attachment) {
Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
msIntent.setType(HTTP.PLAIN_TEXT_TYPE);
msIntent.putExtra("sms_body", "hey there, this is an test SMS");
msIntent.putExtra(Intent.EXTRA_STREAM, attachment);
startActivity(intent);
}
Actions can be among: ACTION_SENDTO, ACTION_SEND or ACTION_SEND_MULTIPLE
URI Schema's: sms:<phone_number>, smsto:<phone_number>, mms:<phone_number>, mmsto:<phone_number>
MIME Types could be like: "text/plain", "image/*", "video/*"
More Posts related to Android,
- Change Android Toast background color
- Maven : java.lang.ClassNotFoundException: Xmx512m
- This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView) Lint Error
- Android Alert Dialog with Checkboxes example
- Android Error Generating Final Archive - Debug Certificate Expired
- How to add Newline to text in Android TextView
- Read Text file from SD Card : Android Programming
- [FIX] AndroidRuntime: FATAL EXCEPTION: main - java.lang.RuntimeException NullPointerException
- ActivityManager Warning: Activity not started, its current task has been brought to the front
- INSTALL_FAILED_INSUFFICIENT_STORAGE Android Error
- Android Developers Bluetooth Tutorial
- java.lang.ClassNotFoundException android.support.v7.widget.Toolbar [Fix]
- Android: Save Data in local Db using Android Room
- Channel 50 SMSes received every few minutes Android Phones
- 21 Useful Android Emulator Short-cut Keyboard Keys
- Changing Android Intent Tittle using java code
- Android : No Launcher activity found! Error
- How to change TextView or EditText Text Color on Focus and on Press
- How to display Toast on Button Click : Android
- Android : Execute some code after back button is pressed
- Stop android adb service from command prompt or terminal
- [Soluiton] You already have the latest version of Android Studio installed
- Create Custom Android AlertDialog
- Android R Cannot Be Resolved To A Variable
- How to make Android EditText not editable
More Posts:
- 97 Useful Notepad++ Keyboard Shortcuts - NotepadPlusPlus
- How to save IntelliJ IDE Console logs to external log file - Android-Studio
- [Fix] Modern authentication failed here, but youll still be able to sign in. Your status code is 4c7 - Microsoft Teams - Teams
- Change Android EditText Cursor Height - Android
- Quick steps to install Nginx on Ubuntu Linux - Ubuntu
- Update SharePoint Online List Item using REST API, HTML, Spfx, Postman - SharePoint
- Submit html form on dropdown menu value selection or change using javascript - JavaScript
- How to make jsfiddle bootstrap ready - CSS