From 02a849272a76e8d3a0069357350dc538ed4e97d5 Mon Sep 17 00:00:00 2001 From: PanZhiyue <202422280902@std.uestc.edu.cn> Date: Tue, 17 Dec 2024 22:12:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 安卓APP.md => README.md | 378 ++++++++++++++++++++-------------------- 1 file changed, 189 insertions(+), 189 deletions(-) rename 安卓APP.md => README.md (96%) diff --git a/安卓APP.md b/README.md similarity index 96% rename from 安卓APP.md rename to README.md index cea192f..fdc752b 100644 --- a/安卓APP.md +++ b/README.md @@ -1,190 +1,190 @@ -# 安卓APP - -## 目的 - -1. 实现页面按钮跳转页面 -2. 点击按钮后,页面显示来自JNI的字符串 - -## 实验步骤 - -### 1. 准备开发环境 - -- Android Studio -- JDK -- NDK(创建项目时会自动部署) -- CMake(创建项目时会自动部署) - -### 2. 创建一个原生C++安卓项目 - -![image-20241217213119132](images/image-20241217213119132.png) - -> 部署原生C++安卓项目时,路径中不能有空格 -> -> 使用了API 28: Android 9.0 - -### 3. 主页面添加按钮 - -在`MainActivity.java`中添加一个按钮,点击后跳转到`SecondActivity` - -``` -package com.example.jnidemoapp; - -import android.content.Intent; -import android.os.Bundle; -import android.view.View; -import android.widget.Button; -import androidx.appcompat.app.AppCompatActivity; - -public class MainActivity extends AppCompatActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - // 页面跳转按钮 - Button button = findViewById(R.id.button_go_to_second); - button.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(MainActivity.this, SecondActivity.class); - startActivity(intent); - } - }); - } -} -``` - -### 4. 创建SecondActivity.java - -新建`SecondActivity.java`文件,显示来自JNI的字符串 - -``` -package com.example.jnidemoapp; - -import android.os.Bundle; -import android.widget.TextView; -import androidx.appcompat.app.AppCompatActivity; - -public class SecondActivity extends AppCompatActivity { - - // 加载本地库 - static { - System.loadLibrary("jnidemoapp"); - } - - // 声明一个本地方法 - public native String stringFromJNI(); - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_second); - - // 显示 JNI 返回的字符串 - TextView textView = findViewById(R.id.text_jni_string); - textView.setText(stringFromJNI()); - } -} -``` - -### 5. 调整界面布局 - -- 在`activity_main.xml`中添加一个按钮: - ``` - - - -