SMS without Sending and delivery Notification

Working on SMS in Android is very simple, if you don’t want sending and delivery notification. While working on SMS API’s in Android we have to pass five arguments which are destination address(i.e user Phone number whom you want to send sms), Source address (i.e user’s number which is null by default), Message Part, sending intent and delivery Intent. For better understanding first go without sending and delivery notification, Later I’ll share those thing also.

Source code :

Layout Designing: create a xml file named main.xml and add two TextView and two EditText and one Button.

main.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
>
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”Enter the phone number of recipient”
/>
<EditText
android:id=”@+id/txtPhoneNo”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
/>
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”Message”
/>
<EditText
android:id=”@+id/txtMessage”
android:layout_width=”fill_parent”
android:layout_height=”150px”
android:gravity=”top”
/>
<Button
android:id=”@+id/btnSendSMS”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”Send SMS”
/>
</LinearLayout>

mainifest.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
package=”com.example.sms”
android:versionCode=”1″
android:versionName=”1.0″ >
<uses-sdk android:minSdkVersion=”15″ />
<uses-permission android:name=”android.permission.SEND_SMS”/>
<uses-permission android:name=”android.permission.RECEIVE_SMS”/>
<application
android:icon=”@drawable/ic_launcher”
android:label=”@string/app_name” >
<activity android:name=”.SMSActivity” android:label=”@string/app_name” >
<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application>
</manifest>

MainActivity.java
package com.example.sms;

import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SMSActivity extends Activity {
Button btnSendSMS;
EditText txtPhoneNo;
EditText txtMessage;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
txtPhoneNo = (EditText) findViewById(R.id.txtPhoneNo);
txtMessage = (EditText) findViewById(R.id.txtMessage);
btnSendSMS.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String phoneNo = txtPhoneNo.getText().toString();
String message = txtMessage.getText().toString();
if (phoneNo.length() > 0 && message.length() > 0)
sendSMS(phoneNo, message);
else
Toast.makeText(getBaseContext(),”Enter both phone number and message.”, Toast.LENGTH_SHORT).show();
}
});
}
// —sends an SMS message to another device—
private void sendSMS(String phoneNumber, String message) {
SmsManager sms = SmsManager.getDefault();

//Here i’m passing null values as sending and delivering Intent
sms.sendTextMessage(phoneNumber, null, message, null, null);
}
}

If You Have Any Problem or Suggestion For Me Then Drop Me a Mail. I Will Wait For Your Anticipated Feedback and Suggestion.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s