Oracle by Example branding Develop an Android Mobile Application Using Oracle Mobile Cloud Service

part 0Before You Begin

This lab will show you how to develop an Android mobile application using Oracle Mobile Cloud Service (MCS).

Background

MCS is a cloud service that provides a unified hub for developing, deploying, maintaining, monitoring, and analyzing your mobile apps and the resources that they rely on.

What Do You Need?


part 1Create Mobile Backend

A mobile backend is the server-side companion to your mobile application. It provides secure access to services like storage, notifications, user management, and custom APIs.

To create a mobile backend do the following:

  1. Log in your MCS instance and click the menu and select Mobile Backends.
  2. Click the New Mobile Backend button.
  3. Enter MCS_QL_Test and click Create.
  4. Select Settings and copy the following to a handy place on your system. We'll use this information later in this tutorial.
    • Mobile Backend ID
    • Anonymous Key
    • Base URL

Keep your Backend open because you will be using it in the next steps.


part 2Create Storage Collection

Now you'll create a storage collection in MCS and add an image to it. This collection will serve as container for your mobile application.

  1. In the left navigation bar of the mobile backend, click Storage.
  2. Click New Collection.
  3. Create a collection called Customer_Images.
  4. In the New Collection dialog, select Shared.
  5. Click Create
  6. In the Read-Only field, type FIF_Technician.

    This ensures that only users with that role have access to that collection, including the user you've set up in the previous part.

  7. Select the Content tab.
  8. Click Upload Files and use the file chooser to select a file to upload, preferably an image.

    After the object is loaded, you'll see it listed on the page.

  9. Copy the ID of that object and paste it somewhere handy. You'll need it a bit later.
  10. Click Mobile Backends and open the MCS_QL_Test backend you created in the Create Mobile Backend part.
  11. Click Storage from the Mobile Backend left menu and then click Select Collections.
  12. Type in the Collections field Customer_Images and then click Select to associate this collection with your Mobile Backend.

part 3Create a Test User

In this part you create a test user to test the running application.

If you did not leave your mobile backend open in a new tab, go to the mobile backend by doing the following in MCS: Click the side menu, Select Applications, Mobile Backends, then select your mobile backend, and click Open.

  1. In the left navbar of your mobile backend, click Mobile User Management.
  2. Click Users and then click New User.
  3. Enter bob as Username.
  4. Enter a valid Email address. Your temporary password will be sent to the email address you enter.
  5. Enter Bob as First Name and Jones as Last Name.
  6. Select the FIF_Technician role from the Roles box by clicking on the Roles text box.
  7. Click Create.

part 4Configure the App

In this section, we'll set up your application to work with MCS.

Use the user name and password you created in the Get Test User step.

MCS allows you to use either OAuth or BasicAuth for authentication. For this lab, we use BasicAuth.

Note: The credentials differ by environment. An environment is a runtime container that holds your mobile backends, APIs, and other artifacts. You typically start work in a development environment, and eventually deploy your artifacts to a staging or production environment.

  1. Create a new directory as follows: C:\Projects\MCS\Android\<YourName>
  2. Unpack the Getting started project that you downloaded.
  3. Open Android Studio and select Import project (Eclipse, ADT, Gradle, etc.)
  4. Select build.gradle in the Select Eclipse or Gradle Project Import dialog box.

    Wait until the project import and gradle sync process finish.

  5. In the project, open main/assets/oracle_mobile_cloud_config.xml and replace the following items:
    • Your_Mobile_Backend_Name.
    • Your_Base_Url
    • Your_Mobile_Backend_ID
    • Your_Anonymous_Key
    
        <?xml version="1.0" encoding="utf-8" ?>
        <mobileBackends>
        <!--Here are the settings for a single mobileBackend.
        For those apps with multiple mobileBackends, you might need to add
        settings one by one below-->
        <mobileBackend>
            <!--Add the name and version of your mobileBackend as values here-->
            <mbeName>YOUR_MOBILE_BACKEND_NAME</mbeName>
            <mbeVersion>1.0</mbeVersion>
            <!--Set to true if the current mobileBackend is the default one-->
            <default>true</default>
            <!--The base URL goes here-->
            <baseUrl>YOUR_BASE_URL</baseUrl>
            <!--Set it true if you want to get analytics information from UI-->
            <enableAnalytics>true</enableAnalytics>
            <!--Set it true if you want to get logging information in Logger-->
            <enableLogger>true</enableLogger>
            <authorization>
                <offlineAuthenticationEnabled>true</offlineAuthenticationEnabled>
                <authenticationType>basic</authenticationType>
                <basic>
                    <mobileBackendID>YOUR_MOBILE_BACKEND_ID</mobileBackendID>
                    <anonymousKey>YOUR_ANONYMOUS_KEY</anonymousKey>
                </basic>
            </authorization>
        </mobileBackend>
    </mobileBackends>
    
    
  6. In the file

    src/main/java/oracle/cloud/mobile/gettingstarted/DownloadActivity.java, find the following lines and replace the values accordingly.

    private String mCollectionID = Customer_Images;
    private String mObjectID = with the ID of the image that you uploaded to the collection in the Create Storage Collection part.
    private String mPictureObjectID = with the same value of the previous field.
    

part 5Run the App

  1. Before running the app in Android studio:
    1. Click Tools
    2. Click Android
    3. Click AVD Manager
  2. In the AVD Manager dialog box, click Create Virtual Device...
  3. Select Nexus 5X and click Next.
  4. Accept the default values and click Next.
  5. Verify the configuration and change it as needed and click Finish when ready.

    Your device must appear in Your Virtual Devices dialog box.

  6. From the Actions column, click the Start button depicted as a green arrowhead.
  7. In Android Studio, choose Run -> Run 'Getting Started'.

    Android Studio will build the application and then launch it in the Android emulator.

  8. Select the Nexus 5X device you created in the AVD Manager, and click OK.
  9. In the running application enter bob as user name and the password you received by email, and click Sign In.
  10. Click Download Incident and then Download Photo.

The image you previously added to the storage collection should display in the emulator.

You've made contact!


Want to Learn More?