This video shows the simple steps to create an Android App which can be used to send SMS pro-grammatically to any number. The advantage of this App is that it does not opens the default Message App of your phone and will directly send the SMS from your App. So, if you want to design an App which sends some message or data automatically to a number via sms then this can be used.
In this video first it creates simple design by placing one push button and two Edit Text Boxes. The edit text boxes are used to take inputs such as numbers and message. In the Java code it is shown how SmsManager class is used to create a local SmsManager variable. Then it uses sendTextMessage method to send the text message to the destination phone number.
This video also shows how AndroidManifest.xml file can be modified to seek permission to access Read and Send SMS. In java code, the approval to read and send SMS from the user is asked by using the requestPermission method of ActivityCompat. Once the permission is granted in the Oncreate method of the main code, the App is able to send the SMS from the Phone. Please watch this video to see the details on this.
Please subscribe to the channel to learn more about tips and tricks of Android App Development.
We will be glad to hear from you regarding any query, suggestions or appreciations at: programmerworld1990@gmail.com
Source Code:
package com.example.mysendsmsapp;
import android.Manifest;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.EditText;public class MainActivity extends AppCompatActivity {
private EditText editTextNumber;
private EditText editTextMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.SEND_SMS, Manifest.permission.READ_SMS}, PackageManager.PERMISSION_GRANTED);
editTextMessage = findViewById(R.id.editText);
editTextNumber = findViewById(R.id.editTextNumber);
}public void sendSMS(View view){
String message = editTextMessage.getText().toString();
String number = editTextNumber.getText().toString();SmsManager mySmsManager = SmsManager.getDefault();
mySmsManager.sendTextMessage(number,null, message, null, null);
}
}
<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
package=”com.example.mysendsmsapp”><uses-permission android:name=”android.permission.SEND_SMS”/>
<uses-permission android:name=”android.permission.RECEIVE_SMS”/>
<uses-permission android:name=”android.permission.READ_SMS”/><application
android:allowBackup=”true”
android:icon=”@mipmap/ic_launcher”
android:label=”@string/app_name”
android:roundIcon=”@mipmap/ic_launcher_round”
android:supportsRtl=”true”
android:theme=”@style/AppTheme”>
<activity android:name=”.MainActivity”>
<intent-filter>
<action android:name=”android.intent.action.MAIN” /><category android:name=”android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application></manifest>
Top posts/ comments from YouTube channel:
you are just creating sending sms app not auto sending sms
—-
Yes, you are right, in this video I have shown how to create a custom SMS App. But you can use this concept and code for any use case where you want to send the messages automatically in the background without accessing the SMS App of your phone.One such use case is to send the location of your phone automatically over SMS. You can watch my below video for details on this using the YouTube link: https://youtu.be/FknRti6n_F8
I am pretty sure once you watch this use case you will appreciate the concept shown in this video.
—-The automation part has a million possibilities. You could simply add a timer and send the text at an exact date/time in the future like an alarm clock. This is a good tutorial video to get you started.
—-
Great, Thank you for sharing us.
Supper, It’s working, thank your for sharing us.