0
votes
    private Response.Listener<JSONObject> awsCognitoResponseListener = new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                bar.setProgress(50);
                Log.d("awsCognito Response:", jsonObject.toString());
                try {
                    strIdentityPoolID = jsonObject.getString("IdentityPoolId");
                    identityID = jsonObject.getString("IdentityId");
                    strToken = jsonObject.getString("Token");
                    developerProviderName = jsonObject.getString("DeveloperProviderName");
                    // Toast.makeText(getActivity(), IdentityPoolId, Toast.LENGTH_SHORT).show();
                    File fileToUpload = new File(AppConstants.MAIN_DIRECTORY + File.separator + "Recordings" + "/" + chosenFile);
                    Log.v(TAG, fileToUpload.getPath());
                    Uri uri = Uri.fromFile(fileToUpload);
                    Log.v(TAG, uri.getPath());
                    HomeActivity parentActivity = (HomeActivity) getActivity();
                    /*Developer Authentication Access*/
                    AWSAsyncTask mAwsAsyncTask = new AWSAsyncTask();
                    mAwsAsyncTask.execute();
                } 
                catch (Exception e) 
                {
                    e.printStackTrace();
                }

            }
        };
   private class AWSAsyncTask extends AsyncTask<Void, String, String> 
    {
        private String errorResponse;
        @Override
        protected void onPreExecute() 
        {
            super.onPreExecute();
        }
        @Override
        protected String doInBackground(Void... voids) {
            PutObjectResult putResponse = null;
            CognitoParams cognitoParams = new CognitoParams();
            cognitoParams.setIdentityPoolId(strIdentityPoolID);
            cognitoParams.setIdentityId(identityID);
            cognitoParams.setDeveloperProviderName(developerProviderName);
            cognitoParams.setRegions(getRegion());
            DeveloperAuthenticationProvider developerProvider = new DeveloperAuthenticationProvider(null, getActivity(), cognitoParams);
            CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(getActivity(),developerProvider,getRegion());
            Map<String, String> logins = credentialsProvider.getLogins();
            if (logins == null) 
            {
               logins = new HashMap<String, String>();
            }
            logins.put(AppConstants.DEVELOPER_PROVIDER, strToken.trim());
            credentialsProvider.setLogins(logins);
            try 
            {
                AmazonS3Client s3Client = new AmazonS3Client(credentialsProvider);
                File fileToUpload = new File(AppConstants.MAIN_DIRECTORY + File.separator + "Recordings" + "/" + chosenFile);
                s3Client.setRegion(Region.getRegion(getRegion()));
                PutObjectRequest putRequest = new PutObjectRequest(BucketName, S3FileName, fileToUpload);
                putResponse = s3Client.putObject(putRequest);
                Log.v("Response bimal: ", putResponse.toString());
                return putResponse.toString();
            } 
            catch (NotAuthorizedException e) 
            {
                Log.e(TAG, e.getErrorMessage());
                errorResponse = e.getErrorMessage();
            } 
            catch (InvalidIdentityPoolConfigurationException e) 
            {
                Log.e(TAG, e.getErrorMessage());
                errorResponse = e.getErrorMessage();
            }
            return null;
        }
        @Override
        protected void onPostExecute(String s) 
        {
            super.onPostExecute(s);
            flag_btnClick = 1;
            if (s != null) 
            {
                uploadConfirmAPI();
            } 
            else 
            {
                errorDialog(errorResponse);
            }
        }
    }

Developer Authenticated Identities
developer authenticated identities, you can register and authenticate users via your own existing authentication process, while still using Amazon Cognito to synchronize user data and access AWS resources Using developer authenticated identities involves interaction between the end user device, your backend for authentication, and Amazon Cognito but CognitoCachingCredentialsProvider not set token and identityID

1
It looks like the only text above has been pasted from the manual, and thus it is not clear what you're asking. - halfer
DeveloperAuthenticationProvider pass to CognitoParams and then CognitoCachingCredentialsProvider pass to DeveloperAuthenticationProvider then after logins.put(AppConstants.DEVELOPER_PROVIDER, strToken.trim()); this set to CognitoCachingCredentialsProvider identityID and Token but actually value null so how can set this two value in CognitoCachingCredentialsProvider . if i have debug mode set to value my file upload success. - bimal

1 Answers

2
votes

In your DeveloperAuthenticationProvider you will need to call update(identityId, token).

You should also make sure that the token you are getting back from your back end server is not null.

Have you taken a look at the Cognito Sample that shows how to use Developer Authenticated Identities?:
https://github.com/awslabs/aws-sdk-android-samples/blob/master/CognitoSyncDemo/src/com/amazonaws/cognito/sync/demo/DeveloperAuthenticationProvider.java

Documentation:
http://docs.aws.amazon.com/cognito/latest/developerguide/developer-authenticated-identities.html