android native方法调用

编程入门 行业动态 更新时间:2024-10-23 17:23:17

android native<a href=https://www.elefans.com/category/jswz/34/1771314.html style=方法调用"/>

android native方法调用

adb devices连接设备

Android数据线要用好一点的线,有的劣质线只能充电,不能传输数据。

 手机上找到系统版本,触摸5下打开开发者选项,打开usb调试,手机上确认连接fingerprint

安装ndk support插件

 * MainActivity.java

package com.example.mysdkdemo;import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;public class MainActivity extends AppCompatActivity {static {System.loadLibrary("mysdkdemo");}public native String getStringFromNative();@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}@Overridepublic boolean onTouchEvent(MotionEvent event) {boolean shouldClose = super.onTouchEvent(event);System.out.printf("(%f,%f), keycode=%d", event.getRawX(), event.getRawY(), event.getActionIndex());System.out.println(this.getStringFromNative());return shouldClose;}
}

 *mysdkdemo.cpp

#include <jni.h>
#include <string>extern "C"
JNIEXPORT jstring JNICALL
Java_com_example_mysdkdemo_MainActivity_getStringFromNative(JNIEnv *env, jobject thiz) {std::string hello = "Hello from C++";return env->NewStringUTF(hello.c_str());
}

运行,手机上触摸屏幕

* CMakeList.txt


# For more information about using CMake with Android Studio, read the
# documentation: .html# Sets the minimum version of CMake required to build the native library.cmake_minimum_required(VERSION 3.22.1)# Declares and names the project.project("mysdkdemo")# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.add_library( # Sets the name of the library.mysdkdemo# Sets the library as a shared library.SHARED# Provides a relative path to your source file(s).mysdkdemo.cpp )# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.find_library( # Sets the name of the path variable.log-lib# Specifies the name of the NDK library that# you want CMake to locate.log )# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.target_link_libraries( # Specifies the target library.mysdkdemo# Links the target library to the log library# included in the NDK.${log-lib} )

* sim.bat

for /l %%i in (1,1,1048576) do (echo %%iadb shell input tap 269 707timeout /T 2 /NOBREAKadb shell input tap 584 2099timeout /T 2 /NOBREAKadb shell input keyevent 4timeout /T 2 /NOBREAK
)

更多推荐

android native方法调用

本文发布于:2023-06-13 00:01:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/670307.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   android   native

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!