├── assets ├── switch-env-host.txt └── switch-env-app-info.txt ├── screenshot.png ├── switch-env.apk ├── ic_launcher-web.png ├── screenshot-small.jpeg ├── libs └── trinea-android-common.jar ├── res ├── drawable-hdpi │ ├── switchenv.png │ └── ic_launcher.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ └── ic_launcher.png ├── drawable-xxhdpi │ └── ic_launcher.png ├── values-sw600dp │ └── dimens.xml ├── values │ ├── dimens.xml │ ├── styles.xml │ └── strings.xml ├── values-sw720dp-land │ └── dimens.xml ├── values-v11 │ └── styles.xml ├── values-v14 │ └── styles.xml ├── values-zh-rTW │ └── strings.xml ├── values-zh-rCN │ └── strings.xml └── layout │ └── activity_main.xml ├── src └── cn │ └── trinea │ └── android │ └── switchenv │ ├── constant │ └── Constants.java │ ├── entity │ └── App.java │ ├── control │ └── AppControl.java │ └── MainActivity.java ├── project.properties ├── README.md ├── .gitignore ├── proguard-project.txt ├── AndroidManifest.xml └── LICENSE /assets/switch-env-host.txt: -------------------------------------------------------------------------------- 1 | ## you can added host 2 | api.trinea.cn 42.121.4.189 3 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trinea/android-switch-env/HEAD/screenshot.png -------------------------------------------------------------------------------- /switch-env.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trinea/android-switch-env/HEAD/switch-env.apk -------------------------------------------------------------------------------- /ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trinea/android-switch-env/HEAD/ic_launcher-web.png -------------------------------------------------------------------------------- /screenshot-small.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trinea/android-switch-env/HEAD/screenshot-small.jpeg -------------------------------------------------------------------------------- /libs/trinea-android-common.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trinea/android-switch-env/HEAD/libs/trinea-android-common.jar -------------------------------------------------------------------------------- /res/drawable-hdpi/switchenv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trinea/android-switch-env/HEAD/res/drawable-hdpi/switchenv.png -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trinea/android-switch-env/HEAD/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trinea/android-switch-env/HEAD/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trinea/android-switch-env/HEAD/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Trinea/android-switch-env/HEAD/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /assets/switch-env-app-info.txt: -------------------------------------------------------------------------------- 1 | ## app list be showed in spinner, add like below 2 | ## packageName appName 3 | cn.trinea.android.demo TrineaAndroidDemo 4 | com.qq QQ -------------------------------------------------------------------------------- /res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8dp 4 | 16dp 5 | 24dp 6 | 48dp 7 | 50dp 8 | -------------------------------------------------------------------------------- /res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/cn/trinea/android/switchenv/constant/Constants.java: -------------------------------------------------------------------------------- 1 | package cn.trinea.android.switchenv.constant; 2 | 3 | /** 4 | * Constants 5 | * 6 | * @author Trinea 2013-7-31 7 | */ 8 | public class Constants { 9 | 10 | public static final String PREFERENCES_SELECTED_POSITION = "selected_position"; 11 | } 12 | -------------------------------------------------------------------------------- /res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-14 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Android 开发测试环境切换工具 2 | ==================================== 3 | `一年前周末花半天写的,用着没太多其他需求就没怎么改进,现在源码开放出来,需要的话可以提交 Request 添加更复杂需求` 4 | 原理介绍:[Android 开发测试环境切换工具](http://www.trinea.cn/android/switch-between-development-and-testing-environment/) 5 | ### 1. 功能介绍 6 | 现在大多开发人员都是通过程序中 isDebug 变量表示是否是 Debug 模式,从而确定后台服务器是接入测试环境还是开发环境 7 |
8 | 那么如果没有程序代码呢?如果是已上线某个老版本呢? 9 |
10 | 这个项目的主要功能是修改 Host 文件,从而达到将对线上环境的访问全部指向到测试环境的目的 11 | `PS:手机必须开启了 Root 权限` 12 | 13 | ![screenshot](screenshot.png) 14 | ### 2. 如何设置 15 | 在 SD 卡根目录下 Trinea 文件夹内新建文件 switch-env-host.txt,内容为测试环境和开发环境对应的 Host 16 | 在 SD 卡根目录下 Trinea 文件夹内新建文件 switch-env-app-info.txt,内容为 App 信息,每行信息为包名 空格 应用名 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | # *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Windows thumbnail db 19 | Thumbs.db 20 | 21 | # OSX files 22 | .DS_Store 23 | 24 | # Eclipse project files 25 | .classpath 26 | .project 27 | .settings 28 | 29 | # Android Studio 30 | .idea 31 | #.idea/workspace.xml - remove # and delete .idea if it better suit your needs. 32 | build/ 33 | .gradle 34 | 35 | # Proguard folder generated by Eclipse 36 | proguard/ 37 | 38 | # Log Files 39 | *.log 40 | 41 | # Other 42 | .svn 43 | 44 | -------------------------------------------------------------------------------- /res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/cn/trinea/android/switchenv/entity/App.java: -------------------------------------------------------------------------------- 1 | package cn.trinea.android.switchenv.entity; 2 | 3 | /** 4 | * App 5 | * 6 | * @author Trinea 2013-7-31 7 | */ 8 | public class App { 9 | 10 | private String packageName; 11 | private String appName; 12 | 13 | public App(String packageName, String appName) { 14 | this.packageName = packageName; 15 | this.appName = appName; 16 | } 17 | 18 | public String getPackageName() { 19 | return packageName; 20 | } 21 | 22 | public void setPackageName(String packageName) { 23 | this.packageName = packageName; 24 | } 25 | 26 | public String getAppName() { 27 | return appName; 28 | } 29 | 30 | public void setAppName(String appName) { 31 | this.appName = appName; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 17 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /res/values-zh-rTW/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 環境切換 5 | 初始化中 6 | 切換中 7 | 切換到測試環境 8 | 切換到線上環境 9 | 當前爲測試環境 10 | 當前爲線上環境 11 | 沒有root權限 12 | 讀取hosts文件異常 13 | ----/etc/hosts文件內容---- 14 | 內容爲空 15 | 寫入hosts文件失敗,需要root權限,請在 安全中心-授權管理-root授權管理 打開root授權或使用超級用戶等應用解決 16 | 清除緩存 17 | 清除緩存並打開 18 | 打開應用失敗 19 | 包名不能爲空 20 | 清除中… 21 | 清除應用緩存失敗,需要root權限,請在 安全中心-授權管理-root授權管理 打開root授權或使用超級用戶等應用解決 22 | 清除應用緩存成功 23 | 選擇應用: 24 | ----打開應用---- 25 | 26 | -------------------------------------------------------------------------------- /res/values-zh-rCN/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 环境切换 5 | 初始化中 6 | 切换中 7 | 切换到测试环境 8 | 切换到线上环境 9 | 当前为测试环境 10 | 当前为线上环境 11 | 没有root权限 12 | 读取hosts文件异常 13 | ----/etc/hosts文件内容---- 14 | 内容为空 15 | 写入hosts文件失败,需要root权限,请在 安全中心-授权管理-root授权管理 打开root授权或使用超级用户等应用解决 16 | 清除缓存 17 | 清除缓存并打开 18 | 打开应用失败,请确保应用已安装 19 | 包名不能为空 20 | 清除中… 21 | 清除应用缓存失败,需要root权限,请在 安全中心-授权管理-root授权管理 打开root授权或使用超级用户等应用解决 22 | 清除应用缓存成功 23 | 选择应用: 24 | ----打开应用---- 25 | 26 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SwitchEnv 5 | Switching 6 | initing 7 | Switch To Test Env 8 | Switch To Online Env 9 | Current is test env 10 | Current is online env 11 | No Root Permission 12 | Get Hosts Exception: 13 | ----Content of /etc/hosts:---- 14 | file is empty 15 | Set Hosts Fail, Need to open root permission in Security Manager or use superuser app 16 | Clear Cache 17 | Clear Cache And Open 18 | Package can not be null 19 | Open App Fail, Please ensure the app is installed 20 | Clearing 21 | Clear app cache fail 22 | Clear app cache success 23 | Choice App: 24 | ----Open App---- 25 | 26 | -------------------------------------------------------------------------------- /res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 10 | 11 |