You need a tutorial, not code example. As there are a bunch of pre compiled command line tools, all of which come from a single package installation, that you can use to send SMS, access address book and do other things from the command line.
Install from F-Droid to get access to all of those.
Install from F-Droid to get access to all of those.