Check a File Existence and Read/Write it

While developing a app, I used internal storage to save a file.

  1. Firstly, I needed to check a file existence. For me, this worked. (
    I used like this but it didn’t work. In my thought, it is because I called it in another thread and it made a problem.
  2. There are some functions to do read/write. This page helped me to decide which to use.
  3. Finally, this page solved my problem. It was also related to the thread as I thought.



NavigationView Error While Running an App on a Device

I met NavigationView Error while running my app on a device (API 19).

Error inflating class

It worked well on emulator. Error log showed details like this.

android.view.InflateException: Binary XML file line #11: Error inflating class

android.content.res.Resources$NotFoundException: File res/drawable/bg_nav.xml from drawable resource ID #0x7f020046

Finally, I found a solution. (But, I don’t know the exact reason…)\
My resources were only in drawable-v21 and I copied them to drawable.

How to Connect Android Application with Database in Server, Amazon EC2

  1. Set Up the AWS Mobile SDK for Android (
    1. I used Android Studio and added the aws-android-sdk-core dependency to my app/build.gradle file, along with the dependencies for the individual services that my project will use, as shown below.
      dependencies {
          compile 'com.amazonaws:aws-android-sdk-core:2.2.+'
          // In the document, they used s3 but I used ec2
          compile 'com.amazonaws:aws-android-sdk-ec2:2.2.+'
          compile 'com.amazonaws:aws-android-sdk-ddb:2.2.+'
          // If you don't add ddb-mapper, compiler can't find         com.amazonaws.mobileconnectors.dynamodbv2.dynamodbmapper.DynamoDBMapper which will be imported later.
          compile 'com.amazonaws:aws-android-sdk-ddb-mapper:2.2.+'
  2. Where Should I place AWS Credentials? I referred here.

    public class MainActivity extends AppCompatActivity {
        AmazonS3 s3;
        protected void onCreate(Bundle savedInstanceState) {
            // callback method to call credentialsProvider method.
        public void credentialsProvider(){
            // Initialize the Amazon Cognito credentials provider
            CognitoCachingCredentialsProvider credentialsProvider = new     CognitoCachingCredentialsProvider(
                us-east-1:dbacd6aa-9393-475e-b687-xxxxxxxx;, // Identity Pool ID
                Regions.US_EAST_1 // Region
    *  Create a AmazonS3Client constructor and pass the credentialsProvider.
    * @param credentialsProvider
        public void setAmazonS3Client(CognitoCachingCredentialsProvider credentialsProvider) {
            // Create an S3 client
            s3 = new AmazonS3Client(credentialsProvider);
            // Set the region of your S3 bucket
  3. Store and Retrieve App Data in Amazon Dynamo DB

    1. Create a DynamoDB Table
      I couldn’t find a way to add attributes when I created a table.
      Then I should add them whenever I add new items.
    2. Set Permissions
      1. Log in to the IAM Console.
      2. Select Roles and select the “Unauth” role that Cognito created for you.
      3. Click Edit Policy in Inline Policies.
      4.  Enter a name for your policy and paste in the policy document shown the document, replacing the Resource values with the ARNs for your table and index. (You can retrieve the table ARN from the Details tab of database; then append /index/* to obtain the value for the index ARN.
      5. Click Apply Policy.
    3. To establish mappings, DynamoDB defines annotations.
    4. Specify the region when you create your AmazonDynamoDBClient.
    5.  Interacting with stored objects is synchronous and must be taken off of the main thread.