I'm trying to send a SMS from mobile to another mobile.
The SMS contains a ftp link.
For example, I want to send the following link: ftp://ftp.example.com.
When the user will open the SMS, the link will be like that ftp://ftp.example.com in the message body.
When the user click this link, the chrome browser will show with the link : http://ftp.example.com
Thank's, Idan
If you are using android Built-in SMS app to send the message, then your code be like this-
String smsBody = "ftp://ftp.example.com";
String phNumber = "123456";
Intent smsIntent = new Intent(android.content.Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address",phNumber); //optional, in case you want a default phone number
smsIntent.putExtra("sms_body",smsBody);
startActivity(smsIntent);
If you are using the SmsManager to send message, then the code be like this-
String smsBody = "ftp://ftp.example.com";
String phNumber = "123456";
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phNumber, null, smsBody, null, null);
And don't forget to give the SEND_SMS permission for both.
<uses-permission android:name="android.permission.SEND_SMS" />
Hope this will help you.
Related
I am trying to send text messages to the selected contacts on the phone using the SmsManager but by default it sends the message using the phone GSM message option. My requirement is to show the popup to the user to choose is messaging options such as WHATSAPP, VIBER etc as shown in the image
here is my code
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage("9844598445", null, "Hello There", null, null);
Please help
Try this one
Uri uri = Uri.parse("smsto:" + smsNumber);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", smsText);
startActivity(intent);
What you're doing right now is directly send an SMS through the SDK. If you want to offer the user the option to send it through another installed app, you need to use an Intent:
Uri uri = Uri.parse("smsto:1234567890");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "The SMS text");
startActivity(it);
This question already has an answer here:
Sending SMS programatically not stored in outbox?
(1 answer)
Closed 9 years ago.
I using "sendTextMessage" in android SDK to send message programmatically. But the sent message doesn't show up in the outbox.
public void sendSMS() {
String phoneNumber = "0123456789";
String message = "Hello World!";
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, message, null, null);
}
Is there any other flag for adding the message to the outbox?
The concept of "outbox" depends on the SMS application. You cannot programatically add SMS's to outboxes of SMS applications on the device (there could be more than one). If you want the SMS to be shown in the users default SMS application then use the intent ACTION_SEND to send the SMS
Code for doing it with an intent
Uri uri = Uri.parse("smsto:xxxxxxx");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "THE SMS BODY");
startActivity(intent);
In short, If you want to send it programatically using SMSManager It would not show in the outbox. Use intents for that.
I would like to know if it is possible to send a SMS from an Android tablet using the SMS intent? If this is not possible, what are my options?
I would like to know if it is possible to send a SMS from an Android tablet using the SMS intent?
There isn't really an "SMS" Intent. There are ACTION_SEND and ACTION_SENDTO Intent actions that could result in an SMS being sent.
With respect to "tablets", most devices with above-average screen sizes do not have telephony capability, and therefore cannot do anything with SMSes, let alone send them in response to startActivity() on some Intent.
what are my options?
If you absolutely have to be able to send SMS messages, add <uses-feature android:name="android.hardware.telephony"/> to your manifest, so your app will only be installed on devices that have telephony capability.
If you would like to send SMS messages if that is possible, but work around it if it is not possible, you will want to do three things:
Add <uses-feature android:name="android.hardware.telephony" android:required="false"/> to your manifest
Use PackageManager and hasSystemFeature() to see if you actually have telephony capability at runtime
For devices that have telephony capability, before you call startActivity() on your "SMS Intent", use PackageManager and queryIntentActivities() to see if there is anything on the device that will respond to that Intent, or wrap your startActivity() call in an exception handler to catch the
ActivityNotFoundException
String smsNumber = "your number here";
String smsText = "Your text";
Uri uri = Uri.parse("smsto:" + smsNumber);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", smsText);
startActivity(intent);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("sms:"
+ phoneNumber)));
Try this.
How to check if a tablet has sms service available:
Here the third solution which CommonsWare described in his answer as a method:
public static boolean hasSmsService(Context context)
{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("smsto:123456789"));
PackageManager pm = context.getPackageManager();
List<ResolveInfo> res = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if(res.size() > 0)
{
return true;
}
return false;
}
}
This is wok for you. try it.........
Method :
CAll on button click event.....
sendSMS("Any text",number,sms_string);
Now, declare this one out of oncreate();
public static void sendSMS(String status, String phoneNumber, String message) {
Log.e("", "Page : " + status + ", No : " + phoneNumber
+ ",Message Length: " + message.length() + ", Message : "
+ message);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
}
I have made a program, in which I am sending some text to pre defined contact number, but now I also want to send voice message to that number please let me know how can I do this?
To send text SMS I am using below code:-
String phoneNumber = "XXXX9";
String message = editLocation.getText().toString();
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, message, null, null);
Toast.makeText(getApplicationContext(),
"Message Sent!", Toast.LENGTH_LONG).show();
Refer this link. In this link there is an explaination on how to send images via MMS. you can just replace the image file with the Audio File. you can find the code to send voice message in the Comments of the above link.
Try something like this
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("sms_body", "some text");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url)); // url would point to mp3 file
sendIntent.setType("audio/mp3");
How to send a SMS to many recipients in android? I want to send a SMS to many receivers in my application. I know this code:
Uri smsToUri = Uri.parse("smsto:" + 10086);
Intent intent = new Intent(
android.content.Intent.ACTION_SENDTO, smsToUri);
String message = "hello";
// message = message.replace("%s", StoresMessage.m_storeName);
intent.putExtra("sms_body", message);
startActivity(intent);
This work for single recipient. But How to send the message to many recipients by using "ACTION_SENDTO" intent? That is too say, how to call the third-party application to send a SMS to many recipients in phone?
send sms to multiple numbers:
String strnum="10086;10086;10087;10089";
Uri smsToUri = Uri.parse("smsto:" + strnum);
or for Sending SMS to Multiple numbers using SmsManager see this post
Unable to send sms using SmsManager in Android