Incoming SMS forwarder article cover image

This Android application is designed to fulfill a simple yet powerful purpose - facilitating the effortless forwarding of any SMS to a designated URL.

Imagine scenarios where you wish to send SMS messages directly to the Telegram messenger or automatically transmit SMS containing payment details to your webserver for streamlined money management (by the way, try my simplest expense tracker). These examples merely scratch the surface of the countless possibilities and use-cases this versatile app has to offer.

The best part? It’s absolutely free! Say goodbye to pesky ads and concerns about your data privacy. This application is designed with your convenience and security in mind. Furthermore, the app is open-source, allowing you to explore, customize, and contribute to its ongoing development.

Ready to unlock the potential of SMS automation? Waste no time, simply click the link to download the latest release and revolutionize your workflow.

Understanding App Purpose and Benefits for Your Needs

In the realm of Android phones, the SMS (Short Message Service) plays a crucial role in facilitating communication. However, there are instances where the SMS messages received on your device need to be processed and directed to a webserver for further action. Enter this Android application, which empowers you to effortlessly achieve this.

With the help of this app, you can seamlessly forward any received text message to your desired API endpoint or any designated website URL in real-time. The application operates by comparing the sender’s name or number against specified parameters. When a match is found, the app promptly initiates the process of forwarding the SMS to the specified URL, ensuring a seamless flow of information.

No longer will you be limited by the constraints of isolated SMS conversations. This app opens up a world of possibilities by bridging the gap between your Android device and webserver, streamlining data processing and enabling swift action based on incoming SMS messages.

Whether you seek to automate tasks, enhance communication workflows, or simply harness the power of seamless integration, this Android app is your go-to solution. Embrace the future of SMS forwarding and unlock a world of possibilities.

How to install the application

You can conveniently download the most up-to-date release of this Android application from multiple sources. Simply click the link or use the alternative app store F-Droid.

It’s important to note that this app is not available on the Play Market. The reason behind this lies in Google’s strict policies regarding apps that require the “read SMS” permission but do not serve as the default SMS handler. As this app focuses solely on forwarding text messages, it does not store or perform other SMS-related functionalities, which prevents it from being utilized as a default SMS handler.

Here is a cite from Google Play Policy Center

Restricted Permission:
SMS permission group (e.g. READ_SMS, SEND_SMS, WRITE_SMS, RECEIVE_SMS, RECEIVE_WAP_PUSH, RECEIVE_MMS)

Requirement:
It must be actively registered as the default SMS or Assistant handler on the device.

Apps lacking default SMS, Phone, or Assistant handler capability may not declare use of the above permissions in the manifest.

Rest assured, this limitation in no way undermines the app’s effectiveness or value. It remains a powerful tool dedicated to seamless SMS forwarding, ensuring your messages are efficiently directed to their intended destination without compromising the privacy or security of your SMS data.

How to forward text messages

To get started, begin by installing the application on your device and launching it. Once successfully installed, you can proceed to add new forwarding rules. Simply locate the floating button positioned in the bottom right corner of the app’s interface and give it a press. This action will initiate the process of creating a new forwarding rule tailored to your specific requirements.

Incoming SMS forwarder main screen

To configure your SMS forwarding, enter the sender’s number or name. Typically, the sender’s identifier is a numeric value, but in certain cases, it might be an alphanumeric name. For convenience, it is recommended to copy the sender information from your default SMS messenger application.

If you wish to forward all incoming SMS messages, simply enter an asterisk (*) instead of a specific number or name.

Next, specify the URL to which you want the text messages to be forwarded. This URL serves as the destination for your forwarded messages. Once you have entered the necessary details, simply press the “ADD” button to create and save the forwarding rule.

Incoming SMS forwarder new forwarding rule dialog

After successfully creating a text message forwarding rule, you will find it listed in the app’s interface. This list provides an overview of all your configured forwarding rules for easy management and reference. If you wish to make any modifications or remove a rule altogether, simply locate the corresponding rule in the list and press the “Delete” button.

Incoming SMS forwarder delete forwarding rule dialog

Starting from this point onward, each incoming SMS will undergo a comparison process with the sender’s specified number or name that you have entered. In the event of a match, the text message will be forwarded to the URL you provided.

It is important to note that the forwarded message will be sent as a request with a JSON payload. This payload contains the relevant information from the original SMS message. To help you better understand the structure, here is an example of a JSON payload that you can expect:

{
  "from": "123456789",
  "text": "example SMS content"
}

In the event that your phone is not connected to the internet or encounters a temporary loss of connection while attempting to send a forwarded SMS, rest assured that the application is designed to handle such scenarios. Upon the recovery of internet connectivity, the application will automatically initiate up to 10 retry attempts to ensure the successful delivery of the message.

Similarly, if a request to the provided URL does not yield a successful response (i.e., the response code is not in the 2XX range), the application will also trigger the retry mechanism. This ensures that even if the initial attempt encounters a failure, subsequent attempts will be made to achieve a successful delivery.

To prevent overwhelming the network or server, there is a delay between each retry attempt. The initial delay is set at a minimum of 10 seconds. Subsequent delays follow an exponential progression, with each delay doubling the previous one. For instance, the second delay will be 20 seconds, the third delay will be 40 seconds, the fourth delay will be 80 seconds, and so on.

For more detailed information and specific references, you can refer to the App repository where you can access the actual documentation and source-code of the application.

SMS forwarder internals in Java

If you’re curious about the inner workings of the application and have a familiarity with the Java programming language, this section provides code snippets to shed light on how the app operates internally.

All relevant files are conveniently located in the main folder, ensuring easy access and organization.

Upon launching the app, the initial step involves invoking the onCreate function. This function serves as the entry point and performs essential tasks. One of the key tasks is checking for the RECEIVE_SMS permission and requesting it if it hasn’t been granted already.

The subsequent step revolves around rendering the SMS forwarding rules. Each rule consists of a sender’s number or name and a corresponding URL. These rules are managed using the ForwardingConfig class, which acts as an abstraction layer on top of the Android SharedPreferences class.

The user interface of the app is designed with simplicity in mind, providing an intuitive experience that allows users to effortlessly add or delete forwarding rules according to their preferences.

Another crucial component of the app is the SmsReceiver. This component is declared as an intent filter in the AndroidManifest.xml file, enabling it to listen for incoming SMS messages.

When your phone receives an SMS, the onReceive function within the SmsReceiver class is triggered. This function plays a pivotal role in processing the received SMS. It retrieves the existing forwarding rules and proceeds to determine if the received text message matches any of the defined rules, ensuring that the message is appropriately handled based on the defined criteria.

String sender = message.getOriginatingAddress();

for (ForwardingConfig config : configs) {
    if (sender.equals(config.getSender()) || config.getSender().equals(asterisk)) {
        JSONObject messageJson = this.prepareMessage(sender, message.getMessageBody());
        this.callWebHook(config.getUrl(), messageJson.toString());
    }
}

Following the matching of the received text message with a forwarding rule, the subsequent step involves sending the text message to the designated URL. To accomplish this task, the app utilizes the WorkManager, which offers several advantages. One notable advantage is that tasks scheduled through WorkManager are designed to persist and continue running even if the app is closed or the phone restarts. This ensures reliable message forwarding and convenient handling of retry attempts in various scenarios.

Within the app’s architecture, the SmsReceiver class passes the URL and text message to the WebHookWorkRequest class. This class is responsible for constructing the work request that specifies the necessary conditions and constraints for performing the web hook task.

Specifically, the WebHookWorkRequest is built with a NetworkType.CONNECTED constraint. This means that a working network connection is a prerequisite for the query to be executed, ensuring that the message forwarding process is carried out only when a network connection is available.

To optimize the retry mechanism, a backoff criteria is implemented. This criteria includes a minimum delay of at least 10 seconds between retry attempts, with subsequent delays increasing exponentially. The simplified exponential function used for calculating the delays follows a pattern of progressive doubling, ensuring progressively longer intervals between each retry attempt.

The simplified exponential function looks like this:

Math.scalb(10, attempt - 1)

Once the app initiates the request to the specified URL, it proceeds to evaluate the outcome of the forwarding rule. In the event that the URL is not in the correct format or other errors are detected within the forwarding rule itself, the WebHookWorkRequest class will not proceed with any further attempts. This ensures that potential issues within the rule configuration are addressed and resolved before subsequent forwarding attempts are made.

However, if the app encounters a network error during the request or receives an error response code from the server, the WorkManager framework steps in and schedules a retry. This retry mechanism ensures that temporary network disruptions or server-related issues do not hinder the successful delivery of the message. WorkManager handles the retry process, providing a reliable and efficient approach to handle temporary setbacks.

Afterword

This explanation provides a simplified overview of the app’s functionality, accompanied by code samples. If you are interested in delving deeper and exploring the complete source code of the SMS forwarder, feel free to explore the available source code. Accessing the source code will provide you with a comprehensive understanding of the implementation details and further insights into the app’s functionality and capabilities.