All Products
Search
Document Center

Create an app in Android Studio

Last Updated: Feb 26, 2021

In this section, you will create an app that causes a Toast to appear when a user taps a button, and obtain the installation package in APK format.

This process mainly includes the following four steps:

  1. Create a project
  2. Write the code
  3. Create a signed file.
  4. Install the app on a cell phone

If you already have a signed native Android development project, you can skip this tutorial and directly create an app in the mPaaS console.

Create a project

  1. Start Android Studio.

    Start AS

  2. Choose File > New > New Project. Set the Application Name, Company domain, and Project Location parameters. If you do not have a company domain, you can use the default value. In this example, set Application Name to My HTML5 Application.
    Configure basic information

  3. Set Target Android Devices to Phone and Tablet and API Target level to API 18: Android 4.3 (Jelly Bean).

    Note: API 18: Android 4.3 (Jelly Bean) is the earliest version that mPaaS and mPaaS Inside can support. In actual production, you can select a version based on your needs.
     Configure basic information 02

  4. Select Empty Activity.
    Select Empty Activity

  5. Select Generate Layout File and Backwards Compatibility (AppCompat). For Activity Name and Layout Name, you can use the default values.
    Configure basic information 04

  6. Click Finish. Now, you have created a project.

Write the code

  1. Open the activity_main.xml file and write the following code in the file.
       
    1. <Button
    2. android:id="@+id/button"
    3. android:layout_width="101dp"
    4. android:layout_height="52dp"
    5. android:text="Button"
    6. tools:layout_editor_absoluteX="142dp"
    7. tools:layout_editor_absoluteY="153dp" />
    Write code step 03
  2. Open the MainActivity class.
    Write code step 1
  3. Write the following code in the MainActivity class.
       
    1. findViewById(R.id.button).setOnClickListener(new View.OnClickListener(){
    2. @Override
    3. public void onClick(View v) {
    4. Toast.makeText(MainActivity.this, "Hello mPaaS!", Toast.LENGTH_SHORT).show();
    5. }
    6. });
    Write code step 2
    Note: If the following dialog box appears after you paste the preceding code in Android Studio, click OK.

     Write code step2 notes
  4. Compile and run the project. Make sure that the code runs normally. Now, you have written the code.

Create a signed file

  1. Choose Build > Generate Signed APK.
    Create a signed file 01

  2. Click Next.
    Create a signed file 02

  3. Click Create new…. If you already have a signed file, click Choosing existing…, select the signed file, and then skip to Step 5.
    Create a signed file 03

  4. Set the parameters and click OK.
    Create a signed file 05

  5. Click Next.
    Create a signed file 06

  6. Set the Build Type parameter based on your needs.
    Create a signed file 07

  7. Select V1 (Jar Signature) for the Signature Versions parameter.
    V1 (Jar Signature) is required and V2 (Full APK Signature) is optional.

    Create a signed file 08

  8. Click Finish. Wait until the signed file appears in the specified directory. Now, you have created a signed file. You can find the signed APK package of your app in the debug folder of your project. The directory is /My HTML5 Application/app/build/outputs/apk/debug.

    Note: After the new signed file is generated, Android Studio automatically compiles and runs the project.

     Create a signed file 09

Install the app on a cell phone

  1. Connect a cell phone to the computer and enable the USB Debugging mode of the cell phone.
  2. Run the project. The Select Deployment Target dialog box appears. Select your mobile phone and click OK.
    Install the app on a mobile phone 01
  3. On your mobile phone, tap Install to install the app.
    Install the app on a mobile phone 02
  4. Open the app and tap BUTTON. The toast “Hello mPaaS!” appears, as shown in the following figure. The display of this toast indicates that the app is installed and can function as expected. Now, you have installed the app on your mobile phone.