How to read and forward certain SMSes programmatically in your Android App? - complete source code

  Рет қаралды 18,062

Programmer World

Programmer World

3 жыл бұрын

This video shows the steps to read the SMSes and forward certain SMS based on a particular condition. In this App, it forwards the SMS to a pre-defined number mentioned in the App's code. However, the number can be taken as an input from the layout also.
The SMS send activity is triggered by a button in the layout. However, it can be automated in the App's code and the forward can be done based on certain condition or time interval.
I hope this video is useful to you. For any questions, suggestions or appreciation please contact us at: programmerworld.co/contact/ or email at: programmerworld1990@gmail.com
The complete source code and details of this video is shared in the below link:
programmerworld.co/android/ho...
The main Java code is copied below also for reference:
package com.programmerworld.smsforwardapp;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private TextView textView;
private String stringNumber = "0000";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.READ_SMS,
Manifest.permission.SEND_SMS},
PackageManager.PERMISSION_GRANTED);
textView = findViewById(R.id.textView);
}
public void buttonForward(View view){
Cursor cursor = getContentResolver().query(Uri.parse("content://sms"), null,null,null,null);
cursor.moveToFirst();
while (cursor!=null){
String stringMessage = cursor.getString(12);
if (stringMessage.contains("programmer")){
SmsManager smsManagerSend = SmsManager.getDefault();
smsManagerSend.sendTextMessage(stringNumber, null, stringMessage, null, null);
textView.setText("Message Sent");
break;
}
textView.setText("Message NOT found");
cursor.moveToNext();
}
}
}

Пікірлер: 40
@codedode3588
@codedode3588 3 жыл бұрын
good and intiresting content
@codedode3588
@codedode3588 3 жыл бұрын
thanks bro
@softdev131
@softdev131 11 ай бұрын
Hi, is there a similar way to read a user's email content ?
@Nitishyadav-qm6nq
@Nitishyadav-qm6nq 3 ай бұрын
It can read fields sms
@rohankudale7997
@rohankudale7997 Жыл бұрын
Hey I'm making an application where I want to display only particular (eg. Transaction) type messages...what should I add in my code to do that? Any suggestions?
@ProgrammerWorld
@ProgrammerWorld Жыл бұрын
In the code shown in this video, it filters the messages based on the "programmer" keyword in the below line of IF statement: if (stringMessage.contains("programmer")) So, if you need you can put filters on the "Transaction" key word. Also, if you want to filter based on the type of the messages (such transaction, order, etc.), you may have to try any one of the below: cursor.getString(X); cursor.getType(X); As of now I am not sure the exact 'X'. I will have to debug the code to get it. If by ay chance you get the correct index ('X' number) then please post it here for everyones knowledge. For reference, the complete details and source code shown in this video is also shared in the below link: programmerworld.co/android/how-to-read-and-forward-certain-smses-programmatically-in-your-android-app-complete-source-code/ Cheers Programmer World programmerworld.co -
@softdev131
@softdev131 11 ай бұрын
Hi Rohan! How is your application going along?
@testingk410
@testingk410 Жыл бұрын
I am not able to read sms in API 13. In the old version, I was able to read but somehow it stop in the new version. Is there any updates in read and receive sms receiver? Please help if any further steps required
@ProgrammerWorld
@ProgrammerWorld Жыл бұрын
Yes, in the latest versions of Android, accessing SMSes by user Apps (non-system Apps) is being limited by the Android OS. By the way, can you please post the error/ exception you are observing now? It will help us to recommend alternate approached in future. For reference, the complete details and source code shown in this video is also shared in the below link: programmerworld.co/android/how-to-read-and-forward-certain-smses-programmatically-in-your-android-app-complete-source-code/ Cheers Programmer World programmerworld.co -
@AutomationJourney
@AutomationJourney Жыл бұрын
What if I want to forward the sms message to a specific mail? Could you please clarify it?
@ProgrammerWorld
@ProgrammerWorld Жыл бұрын
Refer to my below pages which shows the steps to send email. These may help. programmerworld.co/android/how-to-send-email-using-gmail-smtp-server-directly-from-your-android-app/ programmerworld.co/android/how-to-open-and-send-email-using-the-native-client-directly-from-your-android-app-source-code/ For reference, the complete details and source code shown in this video is also shared in the below link: programmerworld.co/android/how-to-read-and-forward-certain-smses-programmatically-in-your-android-app-complete-source-code/ Cheers Programmer World programmerworld.co -
@mmbrazil
@mmbrazil Жыл бұрын
Hi , very nice tutorial, tks On line 42 I am getting this error: "android.database.CursorIndexOutOfBoundsException: Index 6 requested, with a size of 6"
@ProgrammerWorld
@ProgrammerWorld Жыл бұрын
I assume you are getting the error in the below line of code: String stringMessage = cursor.getString(12); The size of "cursor" variable may change depending on the OS version and OEM of the device (as mostly they will put their wrapper on top of the underlying Android OS). From your error message it seems that the max size of the variable is only 5. So, you should only access it using the index 5 (0 to 5 will cover all the 6 indexes of the array). So, changing the call to 5th index will resolve the issue. For reference, details shown in this video is also shared in the below link: programmerworld.co/android/how-to-read-and-forward-certain-smses-programmatically-in-your-android-app-complete-source-code/ Cheers Programmer World programmerworld.co -
@mmbrazil
@mmbrazil Жыл бұрын
@@ProgrammerWorld I changed to 5 but same error message. Is there another way to retrieve a verification code in an SMS and save it in a variable?
@ProgrammerWorld
@ProgrammerWorld Жыл бұрын
Check the size of cursor variable by using cursor.size command. Cheers Programmer World -
@xenonport
@xenonport 3 жыл бұрын
Can it be triggered automatically if the latest message recieved satisfies the condition? If yes how? I want to read the payment recieved sms and as soon as the sms is received it should be forwarded to other number. Please help.
@ProgrammerWorld
@ProgrammerWorld 3 жыл бұрын
Probably no. In theory yes. It can be automated by using the background process to run the App continuously in the background. But in practice, it won't be allowed by the Android OS due to inherent security risks. Cheers Programmer World programmerworld.co -
@arunx20042003
@arunx20042003 2 жыл бұрын
@@ProgrammerWorld so you mean this app has to be kept open inorder to forward sms automatically?
@ProgrammerWorld
@ProgrammerWorld 2 жыл бұрын
@@arunx20042003 No, the concept shown in this video can be used in combination of other logic/ workflow of your App. Say for example, if certain tasks are running in background then those tasks can use this concept to trigger the sms in their process flow. For reference, the complete source code shown in this video is also shared in the below link: programmerworld.co/android/how-to-read-and-forward-certain-smses-programmatically-in-your-android-app-complete-source-code/ Cheers Programmer World programmerworld.co -
@arunx20042003
@arunx20042003 2 жыл бұрын
@@ProgrammerWorld how do I ammes the code that instead of clicking on forward button I need to automatically forward the sms based on condition
@jaishrikrishna3914
@jaishrikrishna3914 Жыл бұрын
@@arunx20042003 You Know How Forward Automatically Incomming sms to Mobile Number or gmail
@shiwendrasingh9854
@shiwendrasingh9854 Жыл бұрын
how can I find latest message from one particular number?
@ProgrammerWorld
@ProgrammerWorld Жыл бұрын
I think the below lines of code will return you the last message: Cursor cursor = getContentResolver().query(Uri.parse("content://sms"), null,null,null,null); cursor.moveToFirst(); String stringMessage = cursor.getString(12); Now, to scan for a message from a certain number you would have browse through the cursor in while loop (by moving to curso.moveToNext) and matching the contact number by using the 2nd index of cursor. Something like: cursor.getString(2) For reference, the complete details and source code shown in this video is also shared in the below link: programmerworld.co/android/how-to-read-and-forward-certain-smses-programmatically-in-your-android-app-complete-source-code/ Cheers Programmer World programmerworld.co -
@mukundbhatia
@mukundbhatia 2 жыл бұрын
when u mentioned read and forward shouldn't it be the messages recieved rather than the one u send i mean there shall be a difference
@ProgrammerWorld
@ProgrammerWorld 2 жыл бұрын
Yes, you are right that SMS sent and received will be different from a user perspective. However, to demonstrate in the emulator (in the video), as the incoming SMS would not have been possible, so, we showed the demo with one of the sent messages. But for all practical purpose this same App will work on a real phone also for received SMSes. The concept remains same. For reference, the complete source code shown in this video is also shared in the below link: programmerworld.co/android/how-to-read-and-forward-certain-smses-programmatically-in-your-android-app-complete-source-code/ Cheers Programmer World programmerworld.co -
@Nitishyadav-qm6nq
@Nitishyadav-qm6nq 3 ай бұрын
Please can we read failed sms and forward sms to another., Please reply soon how possible
@ProgrammerWorld
@ProgrammerWorld 2 ай бұрын
Yes, it can read failed SMSes as well. Yes, SMSes can be forwarded to another number or even Gmail.
@user-we9cz4lg2c
@user-we9cz4lg2c Жыл бұрын
sir please without button click send message automatic.
@ProgrammerWorld
@ProgrammerWorld 10 ай бұрын
Just put the whole code of "buttonForward" method in the "onCreate" method. It will work without any button click or external trigger. For reference, details shown in this video is also shared in the below link: programmerworld.co/android/how-to-read-and-forward-certain-smses-programmatically-in-your-android-app-complete-source-code/ Cheers Programmer World programmerworld.co -
@santafireop3345
@santafireop3345 8 ай бұрын
@@ProgrammerWorldsir i have tried With putting the whole code of Buttonforward in on create method and removing the public void and using the Protected void could tell me what am i doing wrong?
@s.h.a.i5347
@s.h.a.i5347 Жыл бұрын
Hey can you please help. I basically what to do two things. I want it to either send the message to a whatsapp number or email it. And also I want it to do it automatically when a SMS is sent. How do I go about that?
@ProgrammerWorld
@ProgrammerWorld Жыл бұрын
For sending the messages on any other messaging apps automatically, such as Whatsapp or Telegrams, one will have to use the APIs of the respective Apps. For sending over email, such as gmail, SMTP server can be set. One such example is shown in the below: programmerworld.co/android/how-to-send-email-using-gmail-smtp-server-directly-from-your-android-app/ For reference, details shown in this video is also shared in the below link: programmerworld.co/android/how-to-read-and-forward-certain-smses-programmatically-in-your-android-app-complete-source-code/ Cheers Programmer World programmerworld.co -
@rtshdofficial2158
@rtshdofficial2158 Жыл бұрын
bro sms auto forwarder apk dijiye
@ProgrammerWorld
@ProgrammerWorld Жыл бұрын
We do not have the APK file readily available now. However, complete source code is shared in the below page: programmerworld.co/android/how-to-read-and-forward-certain-smses-programmatically-in-your-android-app-complete-source-code/ Cheers Programmer World programmerworld.co -
@user-vf3du3ff1g
@user-vf3du3ff1g Жыл бұрын
what about a face revil
@ProgrammerWorld
@ProgrammerWorld Жыл бұрын
Could you please explain your query with more details? For reference, the complete details and source code shown in this video is also shared in the below link: programmerworld.co/android/how-to-read-and-forward-certain-smses-programmatically-in-your-android-app-complete-source-code/ Cheers Programmer World programmerworld.co -
How to create background process in your Android App?
13:27
Programmer World
Рет қаралды 30 М.
Haha😂 Power💪 #trending #funny #viral #shorts
00:18
Reaction Station TV
Рет қаралды 15 МЛН
Tom & Jerry !! 😂😂
00:59
Tibo InShape
Рет қаралды 61 МЛН
Auto-Read SMS and Autofill OTP Code in Flutter
23:27
Snehasis Ghosh
Рет қаралды 2,4 М.
How Fast Can You Throw a Car in Poly Bridge 3?
15:06
Reid Captain
Рет қаралды 18 М.
Receive and Send SMS in Android Kotlin
22:17
Dr. Parag Shukla
Рет қаралды 17 М.
Most overpowered way to build mobile apps?
8:33
Beyond Fireship
Рет қаралды 729 М.
How to send email using gmail SMTP server directly from your Android App?
17:59
Hack With SMS | SMS Spoofing like Mr. Robot!
11:32
zSecurity
Рет қаралды 989 М.
How to Send Notification in Android
14:15
Codes Easy
Рет қаралды 37 М.
Haha😂 Power💪 #trending #funny #viral #shorts
00:18
Reaction Station TV
Рет қаралды 15 МЛН