Before 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?
- A desktop or laptop computer running Microsoft Windows 7 or later
- Android studio running JDK 7 or greater
- Gradle
- Access to an MCS instance
- The getting started project for the Android platform preconfigured with the MCS SDK
Create 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:
- Log in your MCS instance and click the
menu and select Mobile Backends. - Click the New Mobile Backend button.
- Enter
MCS_QL_Testand click Create. - 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.
Create 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.
- In the left navigation bar of the mobile backend, click Storage.
- Click New Collection.
- Create a collection called Customer_Images.
- In the New Collection dialog, select Shared.
- Click Create
-
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.
- Select the Content tab.
-
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.
- Copy the ID of that object and paste it somewhere handy. You'll need it a bit later.
- Click Mobile Backends and open the MCS_QL_Test backend you created in the Create Mobile Backend part.
- Click Storage from the Mobile Backend left menu and then click Select Collections.
- Type in the Collections field
Customer_Imagesand then click Select to associate this collection with your Mobile Backend.
Create 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.
- In the left navbar of your mobile backend, click Mobile User Management.
- Click Users and then click New User.
- Enter
bobas Username. - Enter a valid Email address. Your temporary password will be sent to the email address you enter.
- Enter
Bobas First Name andJonesas Last Name. - Select the FIF_Technician role from the Roles box by clicking on the Roles text box.
- Click Create.
Configure 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.
- Create a new directory as follows:
C:\Projects\MCS\Android\<YourName> - Unpack the Getting started project that you downloaded.
- Open Android Studio and select Import project (Eclipse, ADT, Gradle, etc.)
- Select build.gradle in the Select Eclipse or Gradle Project Import dialog box.
Wait until the project import and gradle sync process finish.
- In the project, open
main/assets/oracle_mobile_cloud_config.xmland 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> - 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.
Run the App
- Before running the app in Android studio:
- Click Tools
- Click Android
- Click AVD Manager
- In the AVD Manager dialog box, click Create Virtual Device...
- Select Nexus 5X and click Next.
- Accept the default values and click Next.
- Verify the configuration and change it as needed and click Finish when ready.
Your device must appear in Your Virtual Devices dialog box.
- From the Actions column, click the Start button depicted as a green arrowhead.
- In Android Studio, choose Run -> Run 'Getting Started'.
Android Studio will build the application and then launch it in the Android emulator.
- Select the Nexus 5X device you created in the AVD Manager, and click OK.
- In the running application enter
bobas user name and the password you received by email, and click Sign In. - 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?
- See Getting Started to learn more about MCS.
- See this end-to end tutorial to learn more about MCS.
- See the user guide to get more details on working with the features that you want to explore first.
- See Configuring the MCS SDK on Android for a video walkthrough of connecting an Android app to MCS.
Develop an Android Mobile Application Using Oracle Mobile Cloud Service