UniApp calls native methods in Android SDK

UniApp calls native methods in Android SDK

When developing mobile applications, we often need to interact JavaScript code with native code. UniApp is a cross-platform mobile application framework that can build both iOS and Android applications. This article will introduce how to call native methods in Android SDK in UniApp.

  1. Create Android SDK Module
    First, we need to create an Android SDK Module, which will contain the native methods we want to call. This can be done with the following steps:

  2. Open Android Studio, click "File" -> "New" -> "New Module".

  3. In the pop-up dialog box, select "Android Library" and click "Next".

  4. Enter a module name and select the appropriate minimum SDK version. Then click "Finish".

Now that we have created an empty Android SDK Module, we will add the native methods we want to call in it.

  1. Add native method
    In the created Android SDK Module, we need to add the native method we want to call. In the example, we'll add a method called "showToast" that, when called, displays a Toast message.

In the Java folder of the Android SDK Module, find the class file generated by default (usually a class file named after the module name), and add the following code in it:

package 

Guess you like

Origin blog.csdn.net/update7/article/details/132371402