In this section, you will create an application that displays a Toast message when a button is clicked and obtain an installation package in APK format.
This procedure has four main steps:
If you already have a signed, native Android project, you can skip this tutorial and directly create an application in the mPaaS console.
Create a project
Open Android Studio and click File > New > New Project.
In the new project window that appears, select Empty Activity and click Next.
Enter a Name, Package name, and Save location. You can use the default package name. This tutorial uses Scan Application as the Name. Set Minimum SDK to API 18: Android 4.3 (Jelly Bean).
NoteAPI 18: Android 4.3 (Jelly Bean) is the minimum version that mPaaS supports. You can select a different version for production as required.
Click Finish to create the project.
Write the code
Open the
activity_main.xmlfile and add a button using 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" />Open the
MainActivityclass and add the button's click event.findViewById(R.id.button).setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { Toast.makeText(MainActivity.this, "Hello mPaaS!", Toast.LENGTH_SHORT).show(); } });After the code compiles, the coding step is complete.
Create a signature file and sign the project
In Android Studio, click Build > Generate Signed Bundle / APK.
In the window that appears, select APK and click Next.
Click Create new.
Enter the required information and click OK to create the signature. The generated signature file is available in the specified Key store path.
After the content is automatically populated, click Next to add a signature to the project.
Select a build variant as required. Remember the build variant information because you must select the same type when you use the encrypted file. For the signature versions, you must select V1 (Jar Signature). V2 (Full APK Signature) is optional.
Click Finish. After packaging is complete, the signed APK installation package is available in the
debugfolder within your project folder (~\MyHApplication\app\debug). In this tutorial, the installation package is namedapp-debug.apk.
Install the application on a mobile phone
Connect your mobile phone to your computer and enable USB debugging mode on the phone.
Run the project.
Click BUTTON. A Toast message appears, indicating that the application is installed and works as expected.