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,
- Increase Android Emulator Timeout time
- Android : Remove ListView Separator/divider programmatically or using xml property
- Error : Invalid key hash.The key hash does not match any stored key hashes
- How to Change Android Toast Position?
- Android Alert Dialog with Checkboxes example
- Android : No Launcher activity found! Error
- Android Development: Spinners with Example
- Failed to sync Gradle project Error:failed to find target android-23
- INSTALL_FAILED_INSUFFICIENT_STORAGE Android Error
- Disable Fading Edges Scroll Effect Android Views
- How to create Toast messages in Android?
- Channel 50 SMSes received every few minutes Android Phones
- Android xml error Attribute is missing the Android namespace prefix [Solution]
- Create Custom Android AlertDialog
- How To Disable Landscape Mode in Android Application
- Android Development - How to switch between two Activities
- incorrect line ending: found carriage return (\r) without corresponding newline (\n)
- Generate Facebook Android SDK keyhash using java code
- Android Error Generating Final Archive - Debug Certificate Expired
- 21 Useful Android Emulator Short-cut Keyboard Keys
- Android RatingBar Example
- 11 Weeks of Android Online Sessions-15-Jun-to-28-Aug-2020
- Download interrupted: Unknown Host dl-ssl.google.com Error Android SDK Manager
- fill_parent vs match_parent vs wrap_content
- Android : Connection with adb was interrupted 0 attempts have been made to reconnect
More Posts:
- How to come out of dquote prompt in Terminal - macOS/Linux - MacOS
- How to Change Mac Password on macOS Ventura - MacOS
- Your Android SDK is missing, out of date or corrupted SDK Problem - Android-Studio
- How to make div or text in html unselectable using CSS - CSS
- How to get weather details in Command Prompt, macOS or Linux Terminal - HowTos
- Display (Show) bookmarks bar Safari - HowTos
- Cut, Copy and Paste Keyboard Shortcuts on Mac Keyboard - MacOS
- Notepad++ Save Failed - Please check if this file is opened in another program. - NotepadPlusPlus