Any way to send text message without getting a confirmation? - android

Is there any way to send a text message without getting a confirmation? My current code for this is:
String phoneNumber = "1234567";
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("smsto:" + phoneNumber)); // This ensures only SMS apps respond
intent.putExtra("sms_body", "TESTING TEXT MESSAGE! IT WORKS!");
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}

Yes you should use SmsManager. Here is an example:
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);

Related

android java intent putextra sms not working for jio4gvoice

I am trying to sent sms from my android app using
Uri uri = Uri.parse("smsto:"+number);
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "Here you can set the SMS text to be sent");
startActivity(it);
and it is not working when i chose jio4gvoice
Try this I hope this work
startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number, null)));
OR
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage(number, null, msg, null, null);
Note : for second method you need SEND_SMS permission

Android: send immediate SMS

I'm trying to write an app that sends SMS messages.
To do this, I use the following code:
Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
smsIntent.setData(Uri.parse("sms:" + number));
smsIntent.putExtra("sms_body", message);
smsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(smsIntent);
The problem is: when I run it, it shows me a dialog and I need to choose with which app I want to send the message (WhatsApp/Hangouts/Messaging/etc.) and when I choose "Messaging", it only prepares the message and waits for me to press "send".
How can I send the message immediately through "Messaging" (without the dialog and without waiting until "send" is pressed)?
try to use SmsManager API
String phoneNo = "123456";
String msg= "Hello";
buttonSend.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
try {
// send the message
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, msg, null, null);
} catch (Exception e) {
e.printStackTrace();
}
}
});
add this to your manifest :
<uses-permission android:name="android.permission.SEND_SMS" />

(Android) Why i use SmsManager.getDefault().sendTextMessage but apps dont send sms?

I have use SmsManager.getDefault().sendTextMessage but not send sms i want to method programmatically send sms Please see this code
EDIT CODE:
public void sendEmail(View view){
if (hasConnection() == false){
Intent goPop = new Intent(getApplicationContext(),ShowPopup.class);
startActivity(goPop);
finish();
}
statusOfGPS = mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
// Set Email option
final Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",OpsEmail, null));
//Check Send SMS
if (mSMSCheckbox.isChecked()){
SMS = true;
}else{
SMS = false;
}
//Check GPs
if (statusOfGPS == true){
LocationBy = "GPS";
}else{
LocationBy = "INTERNET";
}
setUpAddress();
//SMS true
if (mLocationClient != null && mLocationClient.isConnected() && SMS == true) {
//set massage to send
DescribeText = "This is a Emergency message \n\n PLEASE HELP ME!!! at\n\n "+
addressText+ "\n Location("+LocationBy+"):("+mLocationClient.getLastLocation().getLatitude() + mLocationClient.getLastLocation().getLongitude()+
") \n\n Please check maps <a href='https://maps.google.com/maps?q="+mLocationClient.getLastLocation().getLatitude()+","+mLocationClient.getLastLocation().getLongitude()+"&ll="+mLocationClient.getLastLocation().getLatitude()+","+mLocationClient.getLastLocation().getLongitude()+"&z=17'>here</a>";
//send SMS First
String sent = "android.telephony.SmsManager.STATUS_ON_ICC_SENT";
SmsManager smsManager = SmsManager.getDefault();
PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(sent), 0);
smsManager.sendTextMessage(OpsPhoneNumber, null, DescribeText, pi,null);
//send email
i.putExtra(Intent.EXTRA_SUBJECT, "Emergency Location");
i.putExtra(Intent.EXTRA_TEXT,Html.fromHtml(DescribeText));
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getApplicationContext(), "There are no email clients installed.", Toast.LENGTH_LONG).show();
}
Log.d(TAG, "gps =" + statusOfGPS);
}
}
Next line of //send SMS First
i use
SmsManager.getDefault().sendTextMessage(OpsPhoneNumber, null,
DescribeText, null,null);
and in my manifest file i have:
<uses-permission android:name="android.permission.SEND_SMS"/>
My device to test is android 4.2.2 and 4.1.1
but apps don't send sms how to fix this?
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("", null, "< message body>", null, null);
SmsManager require, SMS_SEND permission in your android mainfest.

How to show the dialog of all the messaging options in android?

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);

send voice message to another contact number

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");

Categories

Resources