aws / amazon-freertos-ble-android-sdk

Android SDK for FreeRTOS Bluetooth Devices.
Apache License 2.0
49 stars 41 forks source link

Not able to Update awsconfiguration.json #31

Closed alpesh-einfochips closed 2 years ago

alpesh-einfochips commented 4 years ago

I want to configure AWSConfiguration on app startup. I want to configure cognito details on login page, but awsconfiguration,json file not able to update because of raw inside file not updated,. Also app working only when awsconfiguration,json inside raw folder.

Please give me suggestion for AWSconfigation before login process.

dachalco commented 4 years ago

Hi @alpesh-einfochips

Just to clarify, you're trying to modify (PoolID, AppClientId, etc.) during app run-time, instead of compiling them in via awsconfiguration.json?

AuthenticatorActivity is responsible for cognito authentication and sign in. It's triggered via Intent in DeviceScanFragment::onCreateView. However it's AuthenticatorActivity's dependencies such as AWSMobileClient (com.amazonaws.mobile.client) that take care of importing the Cognito settings from awsconfiguration.json as well as the sign-in page functionality.

com.amazonaws.* are external libraries that are imported via maven into this project. You may get best answers from asking the developers of com.amazonaws at their git page.

My two cents: AWSConfiguration i.e. (com.amazonaws.mobile.config), used by AWSMobileClient, houses the logic for reading from awsconfiguration.json from read-only raw resources. Instead of importing theses deps, you could build them in your project with edits that allow you to populate AWSMobileClient.awsConfiguration. Editing those libraries, I think you could have the configuration populated by a different file, one that is written by user-input fields. So you'd populate the file from user input settings, then trigger the AuthenticatorActivity which will now read from your custom file instead. Repeating as necessary if authentication fails.

You may also be able to hi-jack AWSMobileClient.awsConfiguration and alter it with your user-input settings before authentication is attempted.

@ravibhagavandas May also be able to supplement or correct my info.

alpesh-einfochips commented 4 years ago

Download code "aws-sdk-android-release_v2.13.5" and change inside class AWSConfiguration for awsconfiguration.json replace with awsconfiguration1.json using method getConfigResourceId. After changes done, compile code and replace aar library file in android app libs folder and bind in build.gradle but still use awsconfiguration.json from raw folder not able to use awsconfiguration1.json.

Please give help me for this issue.

ravibhagavandas commented 4 years ago

@alpesh-einfochips

Android sdk release v2.13.6 onwards supports configuration via an in-memory JSON object as mentioned in the release notes here. To update the mobile app to android SDK version 2.13.6, update the dependencies in app's build.gradle and rebuild the project.

    implementation('com.amazonaws:aws-android-sdk-mobile-client:2.13.6')
    implementation('com.amazonaws:aws-android-sdk-auth-userpools:2.13.6')
    implementation('com.amazonaws:aws-android-sdk-auth-ui:2.13.6')
    implementation 'com.amazonaws:aws-android-sdk-iot:2.13.6'

After upgrading the SDK I was able to create AWSConfiguration using a JSONObject and pass it to AWSMobileClient as follows:

JSONObject jsonObj = new JSONObject();
.....
/** Populate JSON object. **/
.....

AWSConfiguration config = new AWSConfiguration(jsonObj );
AWSMobileClient.getInstance().initialize(getApplicationContext(), config, new Callback<UserStateDetails>() {}
....
alpesh-einfochips commented 4 years ago

Thanks for reply,

Same way IOS app I want to get AWSConfiguration cognito settings from outside instead of json file.

Please help for IOS side also.

ravibhagavandas commented 4 years ago

Hi,

I think api is supported from aws ios sdk 2.11.0 version onwards and this documentation provides more details:

https://github.com/aws-amplify/docs/blob/master/docs/sdk/configuration/fragments/ios/setup-options.md#configure-using-an-in-memory-object

alpesh-einfochips commented 4 years ago

Android App

After adding below code Sign In process working fine, but Create New Account button click on app crash.

Implemented Code :

Updated dependencies in app's build.gradle: implementation('com.amazonaws:aws-android-sdk-mobile-client:2.13.6') implementation('com.amazonaws:aws-android-sdk-auth-userpools:2.13.6') implementation('com.amazonaws:aws-android-sdk-auth-ui:2.13.6') implementation 'com.amazonaws:aws-android-sdk-iot:2.13.6'

JSonObject initialize instead json file: JSONObject jsonObj = new JSONObject(); ..... / Populate JSON object. / .....

AWSConfiguration config = new AWSConfiguration(jsonObj ); AWSMobileClient.getInstance().initialize(getApplicationContext(), config, new Callback() {}

alpesh-einfochips commented 4 years ago

Android App: Please help me for issue of Create New Account button click on app crash after below changes:

AWSConfiguration config = new AWSConfiguration(jsonObj ); AWSMobileClient.getInstance().initialize(getApplicationContext(), config, new Callback() {}

Please look above conversion for better understanding. Please reply for this issue.

dachalco commented 4 years ago

Hello @alpesh-einfochips

Are you able to provide any error logs reported in Android Studio when the app crashes?

alpesh-einfochips commented 4 years ago

For Android : I know reason for crash of Create New Account, its take awsconfiguration.json file from raw folder inside app. Means Create New account take cognito details from awsconfiguration,json.

I want to take configuration details from outside like we did signin process.

For Signin Process we use below code: JSONObject jsonObj = new JSONObject(); ..... / Populate JSON object. / .....

AWSConfiguration config = new AWSConfiguration(jsonObj ); AWSMobileClient.getInstance().initialize(getApplicationContext(), config, new Callback() {}

Above code working with signin process, and create new account process not use this outside configuration, So how can we provide outside details to create new account like signin ?

Please reply for this..

abhidixi11 commented 2 years ago

I'm closing this issue, please feel free to open a new one.