All Products
Search
Document Center

Mobile Platform as a Service:Create App in Android Studio

Last Updated:Jul 26, 2023

In this section, you will create an app that causes a Toast to appear when a user clicks 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 signature file and add the signature to the project

  4. Install the app on a cell phone

If you already have a native Android development project and it is already signed, you may skip this tutorial and directly Create an app on the mPaaS console.

Create a project

  1. Start Android Studio and choose File > New > New Project.

  2. In the Create New Project dialog box that appears, select Empty Activity and click Next.

  3. Enter the Name, Package name (the default value may be used), and Save location. Enter H5 Application as the Name here. Select API 18: Android 4.3 (Jelly Bean) as the Minimum SDK.

    Note

    “API 18: Android 4.3 (Jelly Bean)” is the earliest version supported by mPaaS. You can select a version based on your needs in the actual production environment.

  4. Click Finish to complete creation of the project.

Write the code

  1. Open the file activity_main.xml and add a button by referring to the following code.

     <Button
         android:id="@+id/button"
         android:layout_width="101dp"
         android:layout_height="50dp"
         android:layout_marginStart="142dp"
         android:layout_marginTop="153dp"
         android:layout_marginBottom="151dp"
         android:text="Button"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent" />
  2. Open the class MainActivity and add the click event for the button.

    findViewById(R.id.button).setOnClickListener(new View.OnClickListener(){
             @Override
             public void onClick(View v) {
                 Toast.makeText(MainActivity.this, "Hello mPaaS!", Toast.LENGTH_SHORT).show();
             }
         });
  3. After the compilation succeeds, you will have completed writing the code.

Create a signature file and add the signature to the project

  1. In Android Studio, choose Build > Generate Signed Bundle / APK.

  2. In the dialog box that appears, select APK and click Next.

  3. Click Create new.

  4. After entering all the required information, click OK and you will complete creating the signature. You can obtain the generated signature file in the specified Key store path.

  5. After the contents are automatically entered, click Next to start adding the signature to the project.

  6. Based on your needs, select Build Variants and then V1 (Jar Signature) as the signature version. Note that V1 (Jar Signature) is required while V2 (Full APK Signature) is optional.

  7. Click Finish. After the packaging is complete, you will find the signed APK installation package for this app in the debug folder of the project directory (~\MyHApplication\app\debug). In this tutorial, the name of the installation package is app-debug.apk.

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.

  3. Click BUTTON, pop up Toast, then it means the app was successfully installed and the expected function was implemented. Now, you have completed installing the app on a cell phone.