Show Compose Sms View in Android

Show compose SMS view in Android

You can use the following code:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("sms:"
+ phoneNumber)));

Make sure you set phoneNumber to the phone number that you want to send the message to

You can add a message to the SMS with (from comments):

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNumber));     
intent.putExtra("sms_body", message);
startActivity(intent);

Send sms from text view with click button

What have you done so far? I would suggest using an implicit intent that triggers an sms client in your phone when the button is clicked, like this:

Uri smsUri = Uri.parse("tel:123456");
Intent intent = new Intent(Intent.ACTION_VIEW, smsUri);
intent.putExtra("sms_body", "sms text");
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);

"sms text" should be your textView text. You can do something like this instead

yourTextView.getText().toString();

Sending SMS programmatically without opening message app

You can send messages from your application through this:

public void sendSMS(String phoneNo, String msg) {
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, msg, null, null);
Toast.makeText(getApplicationContext(), "Message Sent",
Toast.LENGTH_LONG).show();
} catch (Exception ex) {
Toast.makeText(getApplicationContext(),ex.getMessage().toString(),
Toast.LENGTH_LONG).show();
ex.printStackTrace();
}
}

Also, you need to give SEND_SMS permission in AndroidManifest.xml to send a message

<uses-permission android:name="android.permission.SEND_SMS" />

How to compose SMS via intents without recipient

Without appending phone number to URI also works:

    Uri uri = Uri.parse("smsto:");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", "Hello World!");
startActivity(intent);

I guess it works also with ACTION_VIEW action as described in https://stackoverflow.com/a/2372665/813951

How to send SMS from the Android app without making its record in device SMS view?

Yes, the way you are trying to send SMS is by using the shipped messaging application. So it will always record the sent messages. You must use SmsManager to send the SMS.

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);

In this way, your SMS wont be inserted into the list.

Also remember to add this in your manifest

<uses-permission android:name="android.permission.SEND_SMS" />

How to develop an android SMS View?

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

<RelativeLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="fill_parent"
a:layout_height="fill_parent">
<LinearLayout
a:orientation="vertical"
a:layout_height="wrap_content"
a:layout_width="fill_parent">
<EditText
a:id="@+id/smsRecipients"
a:layout_height="wrap_content"
a:layout_width="fill_parent"
a:hint="@string/sms_to_whom"/>
<Button
a:layout_height="wrap_content"
a:layout_width="fill_parent"
a:text="@string/sms_contacts"
a:onClick="onPickContact"/>
</LinearLayout>

<LinearLayout a:layout_alignParentBottom="true"
a:orientation="horizontal"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:paddingTop="5dip"
a:paddingBottom="5dip"
a:paddingLeft="5dip"
a:paddingRight="5dip"
a:background="#dcdcdc">
<EditText
a:id="@+id/smsBody"
a:layout_width="0dip"
a:layout_height="wrap_content"
a:layout_weight="1.0"
a:autoText="true"
a:capitalize="sentences"
a:nextFocusRight="@+id/send_button"
a:hint="@string/sms_enter_message"
a:maxLines="10"
a:inputType="textShortMessage|textAutoCorrect|textCapSentences|textMultiLine"
a:imeOptions="actionSend|flagNoEnterAction"/>
<LinearLayout a:orientation="vertical" a:layout_width="wrap_content" a:layout_height="fill_parent">
<Button
a:id="@+id/smsSendButton"
a:layout_marginLeft="5dip"
a:layout_width="wrap_content"
a:layout_height="0dip"
a:layout_weight="1.0"
a:nextFocusLeft="@+id/smsBody"
a:text="@string/sms_send_abbr"
a:enabled="false"/>
</LinearLayout>
</LinearLayout>

</RelativeLayout>


Related Topics



Leave a reply



Submit