diff --git a/README.md b/README.md index f65dc8716..366a5d13d 100644 --- a/README.md +++ b/README.md @@ -142,13 +142,11 @@ dependencies { implementation 'software.amazon.awssdk.crt:android:0.22.1' } ``` +[Android IoT Samples README](./android/app/src/main/assets/README.md) Replace `0.22.1` in `software.amazon.awssdk.crt:android:0.22.1` with the latest version of the CRT. Look up the latest CRT version here: https://github.com/awslabs/aws-crt-java/releases -#### Caution -You will need to override and provide a ROOT_CERTIFICATE manually from one of the following [certificates](https://www.amazontrust.com/repository/). For overriding default trust store you can use following [method](https://github.com/aws/aws-iot-device-sdk-java-v2/blob/ed802dce740895bcd3b0b91de30ec49407e34a87/sdk/src/main/java/software/amazon/awssdk/iot/AwsIotMqttConnectionBuilder.java#L151-L160). It's a [known problem](https://github.com/aws/aws-iot-device-sdk-java-v2/issues/157). - ## Samples [Samples README](samples) diff --git a/android/app/build.gradle b/android/app/build.gradle index 9ea445870..3c996e8e7 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -22,6 +22,7 @@ android { java.srcDir '../../samples/BasicPubSub/src/main/java' java.srcDir '../../samples/Jobs/src/main/java' java.srcDir '../../samples/Shadow/src/main/java' + java.srcDir '../../samples/CognitoConnect/src/main/java' java.srcDir 'src/main/java' } } diff --git a/android/app/src/main/assets/README.md b/android/app/src/main/assets/README.md index 0e8701918..83168ded7 100644 --- a/android/app/src/main/assets/README.md +++ b/android/app/src/main/assets/README.md @@ -1,14 +1,33 @@ # Android App -Files must be placed in the assets directory -# Required files to run all samples: +[**Return to aws-iot-device-sdk-java-v2 README**](../../../../../../aws-iot-device-sdk-java-v2/README.md) + +# Files used by IoT Samples App +Files must be placed in the assets directory for the sample app to connect to IoT Core. +## Required by all samples: * endpoint.txt - IoT ATS Endpoint + +## Requiret to run BasicPubSub, Jobs, and Shadow samples * certificate.pem - IoT Thing Certificate * privatekey.pem - IoT Thing Private Key +## Required to run Cognito Client sample: +* cognitoIdentity.txt - Cognito identity ID +* signingRegion.txt - Signing region -# Optional files: + +## Optional files: * rootca.pem - override the default system trust store * clientId.txt - specifies --clientId CLI argument * topic.txt - specifies --topic CLI argument * message.txt - specifies --message CLI argument * port.txt - specifies --port CLI argument * thingName.txt - specifies --thingName CLI argument + +# Links to samples +[**BasicPubSub**](../../../../../samples/BasicPubSub/README.md) + +[**Jobs**](../../../../../samples/Jobs/README.md) + +[**Shadow**](../../../../../samples/Shadow/README.md) + +[**CognitoConnect**](../../../../../samples/CognitoConnect/README.md) +##### NOTE: The shadow sample does not currently complete on android due to its dependence on stdin keyboard input. \ No newline at end of file diff --git a/android/app/src/main/java/software/amazon/awssdk/iotsamples/MainActivity.kt b/android/app/src/main/java/software/amazon/awssdk/iotsamples/MainActivity.kt index 5ca732eea..2ab16d605 100644 --- a/android/app/src/main/java/software/amazon/awssdk/iotsamples/MainActivity.kt +++ b/android/app/src/main/java/software/amazon/awssdk/iotsamples/MainActivity.kt @@ -17,7 +17,8 @@ import kotlin.concurrent.thread val SAMPLES = mapOf( "Publish/Subscribe Sample" to "pubsub.PubSub", "Jobs Client Sample" to "jobs.JobsSample", - "Shadow Client Sample" to "shadow.ShadowSample" + "Shadow Client Sample" to "shadow.ShadowSample", + "Cognito Client Sample" to "cognitoconnect.CognitoConnect" ) class MainActivity : AppCompatActivity(), AdapterView.OnItemSelectedListener { @@ -126,9 +127,16 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemSelectedListener { resourceNames.add("endpoint.txt") // Add required files for Samples here - if (name == "pubsub.PubSub" || name == "jobs.JobsSample" || name == "shadow.ShadowSample"){ - resourceNames.add("certificate.pem") - resourceNames.add("privatekey.pem") + when(name) { + "pubsub.PubSub", "jobs.JobsSample", "shadow.ShadowSample" -> { + resourceNames.add("certificate.pem") + resourceNames.add("privatekey.pem") + } + + "cognitoconnect.CognitoConnect" -> { + resourceNames.add("cognitoIdentity.txt") + resourceNames.add("signingRegion.txt") + } } // Copy to cache and get file locations for required files @@ -150,12 +158,34 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemSelectedListener { } if(isResourcesFound) { - args.addAll(arrayOf( - "--endpoint", assetContents("endpoint.txt"), - "--cert", resourceMap["certificate.pem"], - "--key", resourceMap["privatekey.pem"], - "--port", assetContentsOr("port.txt", "8883"), - "--client_id", assetContentsOr("clientId.txt", "android-java-crt-test"))) + args.addAll(arrayOf("--endpoint", assetContents("endpoint.txt"))) + + when(name) { + "pubsub.PubSub" -> { + args.addAll(arrayOf( + "--cert", resourceMap["certificate.pem"], + "--key", resourceMap["privatekey.pem"], + "--port", assetContentsOr("port.txt", "8883"), + "--client_id", assetContentsOr("clientId.txt", "android-java-crt-test"), + "--topic", assetContentsOr("topic.txt", "test/topic"), + "--message", assetContentsOr("message.txt", "Hello World From Android"))) + } + + "jobs.JobsSample", "shadow.ShadowSample" -> { + args.addAll(arrayOf( + "--cert", resourceMap["certificate.pem"], + "--key", resourceMap["privatekey.pem"], + "--port", assetContentsOr("port.txt", "8883"), + "--client_id", assetContentsOr("clientId.txt", "android-java-crt-test"), + "--thing_name", assetContentsOr("thingName.txt", "aws-iot-unit-test"))) + } + + "cognitoconnect.CognitoConnect" -> { + args.addAll(arrayOf( + "--signing_region", assetContents("signingRegion.txt"), + "--cognito_identity", assetContents("cognitoIdentity.txt"))) + } + } // Check for optional root CA file try { @@ -168,16 +198,6 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemSelectedListener { } } catch (e: Exception) {} - if (name == "pubsub.PubSub") { - args.addAll(arrayOf( - "--topic", assetContentsOr("topic.txt", "test/topic"), - "--message", assetContentsOr("message.txt", "Hello World From Android"))) - } else if (name in arrayOf("jobs.JobsSample", "shadow.ShadowSample")) { - args.addAll(arrayOf( - "--thing_name", assetContentsOr("thingName.txt", "aws-iot-unit-test") - )) - } - val main = sampleClass?.getMethod("main", Array::class.java) try {