Recently there was a requirement from customer (major bank) to a create messaging application that can listen for inbound and outbound messages, for the Android-powered BlackBerry PRIV device. I wanted to share my experience of how I implemented the solution by making a sample application. It is useful for developers, if they need to perform some action when a message is sent or received (block it, log it, etc.). At the end, I have provided the GitHub links for downloading the code, for you to extend and use for your own needs.
Implementation:
When the sample application is installed on the device, any SMS you receive or send is reflected by toast. A service class is used which runs at back-end and listens to the messages. A Content observer is registered in the onStart() method of the service, to listen for the changes in the content of the messages.
For incoming messages, I have also registered a Broadcast receiver which will provide additional information regarding the sender, number and message body.
Toast.makeText(this, "MyService Completed or Stopped.", Toast.LENGTH_SHORT).show();
}
Our sample application even supports Android permissions starting from the Marshmallow release (API Level 23).
Security for the application is provided by the BID framework. By using the BID framework in our application, we can ensure that the application will only run when the device is in a secure state. Currently this feature is supported only on BlackBerry devices running the Android operating system.
Support for Enterprises:
The application can also be leveraged in enterprise environments, as it is also supported when used with Android for Work and Samsung Knox frameworks.
For more information about the installation and usage of Android for Work, feel free to refer to: Developing Apps for Work
GitHub source code:
The source code of the application is available here.
Code for the application developed in BID framework can be found here.