init: Android backup GUI project
This commit is contained in:
15
.github/copilot-instructions.md
vendored
Normal file
15
.github/copilot-instructions.md
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
- [ ] Clarify Project Requirements
|
||||||
|
- [x] Scaffold the Project
|
||||||
|
- [ ] Customize the Project
|
||||||
|
- [ ] Install Required Extensions
|
||||||
|
- [ ] Compile the Project
|
||||||
|
- [ ] Create and Run Task
|
||||||
|
- [ ] Launch the Project
|
||||||
|
- [ ] Ensure Documentation is Complete
|
||||||
|
|
||||||
|
# 项目说明
|
||||||
|
本项目为 backup_script 脚本提供 Android 图形化操作界面,支持本地运行脚本、参数配置、结果展示。
|
||||||
|
|
||||||
|
## 进度说明
|
||||||
|
- 已完成项目结构搭建与主要文件生成。
|
||||||
|
- 下一步将完善脚本调用、参数配置与界面交互细节。
|
||||||
23
README.md
Normal file
23
README.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Android Backup GUI
|
||||||
|
|
||||||
|
本项目为 backup_script 脚本提供 Android 图形化操作界面,支持本地运行脚本、参数配置、结果展示。
|
||||||
|
|
||||||
|
## 功能规划
|
||||||
|
- 通过界面选择/配置脚本参数
|
||||||
|
- 一键执行 backup_script/tools.sh
|
||||||
|
- 显示执行日志和结果
|
||||||
|
|
||||||
|
## 技术栈
|
||||||
|
- Kotlin
|
||||||
|
- Android Studio 项目结构
|
||||||
|
|
||||||
|
## 目录结构
|
||||||
|
- app/ 主要 Android 源码
|
||||||
|
- scripts/ 存放 shell 脚本(如 tools.sh)
|
||||||
|
|
||||||
|
## 使用说明
|
||||||
|
1. 用 Android Studio 打开本项目
|
||||||
|
2. 运行 app 模块
|
||||||
|
3. 在界面中配置参数并执行脚本
|
||||||
|
|
||||||
|
> 注意:需确保 Android 设备具备 shell 权限(如 root 或 Termux 环境),否则无法直接运行 shell 脚本。
|
||||||
20
app/AndroidManifest.xml
Normal file
20
app/AndroidManifest.xml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.example.androidbackupgui">
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:allowBackup="true"
|
||||||
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
|
android:supportsRtl="true"
|
||||||
|
android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
|
||||||
|
<activity android:name=".MainActivity">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
||||||
44
app/MainActivity.kt
Normal file
44
app/MainActivity.kt
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
package com.example.androidbackupgui
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.widget.*
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import java.io.BufferedReader
|
||||||
|
import java.io.DataOutputStream
|
||||||
|
import java.io.InputStreamReader
|
||||||
|
|
||||||
|
class MainActivity : AppCompatActivity() {
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
|
val paramInput = findViewById<EditText>(R.id.paramInput)
|
||||||
|
val runButton = findViewById<Button>(R.id.runButton)
|
||||||
|
val resultView = findViewById<TextView>(R.id.resultView)
|
||||||
|
|
||||||
|
runButton.setOnClickListener {
|
||||||
|
val params = paramInput.text.toString()
|
||||||
|
val result = runShellScript(params)
|
||||||
|
resultView.text = result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun runShellScript(params: String): String {
|
||||||
|
// 假设脚本已复制到 /data/data/com.example.androidbackupgui/files/scripts/tools.sh
|
||||||
|
val scriptPath = filesDir.absolutePath + "/scripts/tools.sh"
|
||||||
|
val cmd = "sh $scriptPath $params"
|
||||||
|
return try {
|
||||||
|
val process = Runtime.getRuntime().exec(arrayOf("su", "-c", cmd))
|
||||||
|
val reader = BufferedReader(InputStreamReader(process.inputStream))
|
||||||
|
val output = StringBuilder()
|
||||||
|
var line: String?
|
||||||
|
while (reader.readLine().also { line = it } != null) {
|
||||||
|
output.append(line).append("\n")
|
||||||
|
}
|
||||||
|
reader.close()
|
||||||
|
output.toString()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
"执行失败: ${e.message}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
29
app/activity_main.xml
Normal file
29
app/activity_main.xml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="16dp">
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/paramInput"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="输入脚本参数" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/runButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="运行脚本" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/resultView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="结果输出..."
|
||||||
|
android:background="#EEE"
|
||||||
|
android:padding="8dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
27
app/build.gradle
Normal file
27
app/build.gradle
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
apply plugin: 'com.android.application'
|
||||||
|
apply plugin: 'kotlin-android'
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 34
|
||||||
|
defaultConfig {
|
||||||
|
applicationId "com.example.androidbackupgui"
|
||||||
|
minSdkVersion 24
|
||||||
|
targetSdkVersion 34
|
||||||
|
versionCode 1
|
||||||
|
versionName "1.0"
|
||||||
|
}
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
minifyEnabled false
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.0"
|
||||||
|
implementation 'androidx.core:core-ktx:1.12.0'
|
||||||
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
|
implementation 'com.google.android.material:material:1.11.0'
|
||||||
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
|
}
|
||||||
23
build.gradle
Normal file
23
build.gradle
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// Top-level build file
|
||||||
|
buildscript {
|
||||||
|
ext.kotlin_version = '1.9.0'
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath 'com.android.tools.build:gradle:8.2.0'
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task clean(type: Delete) {
|
||||||
|
delete rootProject.buildDir
|
||||||
|
}
|
||||||
2
scripts/README.md
Normal file
2
scripts/README.md
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# 该目录用于存放将要在 Android 端执行的 shell 脚本
|
||||||
|
# 请将 backup_script/tools.sh 复制到此目录下,并确保脚本有可执行权限
|
||||||
2
settings.gradle
Normal file
2
settings.gradle
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
rootProject.name = "android-backup-gui"
|
||||||
|
include ':app'
|
||||||
Reference in New Issue
Block a user