#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#CommandLineArgs:
#MergeLibraries: True
#End Region
'select JavaObject library for this project
'requires Java 11 due to static interface method invocations
'get jar files from https://mvnrepository.com/artifact/software.amazon.awssdk/
'put into AdditionalLibraries directory
#AdditionalJar: sdk-core-2.16.5.jar
#AdditionalJar: auth-2.16.5.jar
#AdditionalJar: regions-2.16.5.jar
#AdditionalJar: protocol-core-2.16.5.jar
#AdditionalJar: apache-client-2.16.5.jar
#AdditionalJar: utils-2.16.5.jar
#AdditionalJar: http-client-spi-2.16.5.jar
#AdditionalJar: aws-core-2.16.5.jar
#AdditionalJar: metrics-spi-2.16.5.jar
#AdditionalJar: profiles-2.16.5.jar
#AdditionalJar: aws-query-protocol-2.16.5.jar
'include service-specific jar files as needed
#AdditionalJar: sns-2.16.5.jar
'get these dependencies from https://mvnrepository.com/
#AdditionalJar: reactive-streams-1.0.3.jar
#AdditionalJar: httpclient-4.5.13.jar
#AdditionalJar: httpcore-4.4.14.jar
#AdditionalJar: commons-logging-1.2.jar
#AdditionalJar: slf4j-api-1.7.30.jar
#AdditionalJar: slf4j-simple-1.7.30.jar
'#AdditionalJar: slf4j-nop-1.7.30.jar
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private Button1 As B4XView
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
DateTime.DateFormat="yyyy-MM-dd HH:mm:ss"
End Sub
Sub Button1_Click
Dim jo As JavaObject = Me
jo.RunMethod("SendSms", Array("access key", "secret access key", DateTime.Date(DateTime.Now), "+12025550113"))
xui.MsgboxAsync("Message sent!", "B4X")
End Sub
#if Java
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.sns.SnsClient;
import software.amazon.awssdk.services.sns.model.PublishRequest;
import software.amazon.awssdk.services.sns.model.PublishResponse;
public static void SendSms(String AccessKey, String SecretAccessKey, String Message, String MobileNumber) {
//Must be one of ("trace", "debug", "info", "warn", "error" or "off"). If not specified, defaults to "info".
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "info");
AwsBasicCredentials awsCreds = AwsBasicCredentials.create(AccessKey, SecretAccessKey);
AwsCredentialsProvider awsCredProv = StaticCredentialsProvider.create(awsCreds);
SnsClient sc = SnsClient.builder()
.region(Region.US_EAST_1)
.credentialsProvider(awsCredProv)
.build();
String SMSMessage = Message;
String mobile = MobileNumber;
PublishRequest pubReq = PublishRequest.builder()
.message(SMSMessage)
.phoneNumber(mobile)
.build();
PublishResponse result = sc.publish(pubReq);
System.out.println(result); // Prints the message ID.
}
#End If