All Products
Search
Document Center

Mobile Platform as a Service:Create an Application in Android Studio

Last Updated:Jul 27, 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 sign the project

  4. Install the application on a mobile phone

If you already have a native Android project and the project has already been signed, skip this tutorial and directly Create an application in 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 a name in Name, enter a package name in Package name, and specify a project location in Save location. Note that the default package name can be used. For example, enter Scan Application in the Name entry box. From the Minimum SDK drop-down list, select API 18: Android 4.3 (Jelly Bean).

    Note

    API 18: Android 4.3 (Jelly Bean)” is the earliest version that the mPaaS supports. You can select a version according to the actual production requirements.

  4. Click Finish. The Create a project procedure is complete.

Write the code

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

     <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 MainActivity class and add a click event to 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. Compile the code. After successful compilation, the Write the code procedure is completed.

Create a signature file and sign 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. Enter all the required information and click OK. The signature creation is complete. You can obtain the generated signature file in the path specified in Key store path.

  5. After the fields are automatically filled, click Next to start signing the project.

  6. Select a build variant in Build Variants as needed. Remember the selected build variant. You need to select the same variant when you use the encrypted file.

    Then select the encrypted version V1 (Jar Signature). Note that V1 (Jar Signature) is required while V2 (Full APK Signature) is optional.

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

Install the application on a mobile 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. This notification indicates that you have successfully installed the application with the expected features. Now you complete the installation of the application on a mobile phone.