Skip to content

GitLab Next

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
TotalCross
TotalCross
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 78
    • Issues 78
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 2
    • Merge Requests 2
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • TotalCross
  • TotalCrossTotalCross
  • Wiki
    • Features
  • sms manager

Last edited by Vaneska Karen Jan 12, 2018
Page history

sms manager

New to TotalCross? Check our homepage and learn more about us!

  • For TotalCross 3.42, we created a way to manage SMS in Android.
  • For Totalcross 4.1.0, we implements sending and receiving data SMS also disables changing the state of the receiver when the application is paused and resumed

You can see the example on GitHub. iOS does not allow handling SMS.

The SmsManager class allows you to send a SMS message and to intercept a received SMS. The SmsManager is a singleton that could be different depending on the current platform. You should get its preferred instance with SmsManager.getDefault().

Send a SMS

To send a SMS, you must call the sendTextMessage(String destinationAddress, String scAddress, String text) method from the SmsManager object. Let us dive in this subject here:

  • destinationAddress is the phone number targeted to receive the message;
  • scAddress is the service center address; if you want to use the default service, just keep it null;
  • text is the message that will de sent to the number destinationAddress using the service center scAddress.

You can check in the example how it is used

When you call this method, your application will call the system's default SMS app.

Intercept received SMS

To intercept a received SMS, you should tell your SmsManager who will do this work for you. The one who will do it is an object that implements the SmsReceiver interface. It is a simple interface with only one method onReceive(SmsMessage), so in the example we created it using lambda. More details of the SmsMessage further on.

With your receiver in hand, you must tell the SmsManager who it is with the registerSmsReceiver(SmsReceiver) or registerSmsReceiver(SmsReceiver receiver, int port) method, like in the example.

If you wish to change something live in the UI, there are some caveats. You should do all the manipulation of the UI as you wish, and only after it is done asks the controls to repaint themselves, but this repaint must run in the main thread:

// repaint on main window
MainWindow.getMainWindow().runOnMainThread(() -> {
    topContainer.repaintNow();
});

Please note that you can only have a single class intercepting SMS at a time; calling the method SmsManager.registerSmsReceiver(SmsReceiver) or SmsManager.registerSmsReceiver(SmsReceiver receiver, int port)

  • will replace the older SmsReceiver with the new one. If you wish to stop intercepting SMS, pass null as the argument to registerSmsReceiver.
  • the port is required to listen to incoming SMS messages and SMS data messages. If you want to listen on the default port, just need a pass -1 port for text messages.

You can see it in the examples, we change the UI between lines 74-79 and we ask to repaint the control between lines 81-85

SmsMessage object

To handle an intercepted SMS, you may want to read it's content and do something with it. It is an object created by the TotalCross VM that contains some info about the SMS. That info are the message body and the originating address. These are available in their respective getters:

  • getDisplayOriginatingAddress() \rightarrow originating address
  • getDisplayMessageBody() \rightarrow message body

We use both of getters in the Github example.

Clone repository
  • 404
  • Configuring masOS Environment
  • Deploy
    • iOS Deploy (Videos)
    • iOS
  • Features
    • Push Notification Firebase
    • fade transition
    • open known files in Android
    • scandit
    • side menu
    • sms manager
    • speech to text
  • Tips
    • Detecting leaking SQLite resources
  • building with maven
  • dagger
  • getting started
View All Pages