【andriod】设备APP开发之各种细节部署和操作

2年前Java源码25871
【andriod】设备APP开发之各种细节部署和操作 一直在尽头 已于2022-10-09 09:50:52修改 12296 收藏 160 分类专栏: 云原生-设备云组态 andriod APP开发实战 文章标签: android android studio gradle 设备云 云原生 于2022-09-04 15:13:20首次发布 云原生-设备云组态 同时被 2 个专栏收录 19 篇文章 4 订阅 订阅专栏 andriod APP开发实战 11 篇文章 0 订阅 订阅专栏

文章目录 前言一、开发工具1、软件介绍2、Android JDK配置3、Android Gradle配置4、Android API配置5、项目依赖配置 二、项目细节详情1、andriodmanifest.xml配置详情2、ExampleInstrumentedTest配置详情3、ExampleUnitTest配置详情4、Utils配置详情5、activity_main.xml配置详情6、Gradle Scripts配置详情build.gradle(Project)build.gradle(Module) 总结


前言

随着工业自动化的不断发展,设备APP也越来越重要,本文就设备APP开发软件配置细节做一个深入详解。


提示:以下是本篇文章正文内容,下面案例可供参考

一、开发工具

使用软件Android Studio 4.1版本

1、软件介绍

Android Studio 是基于 IntelliJ IDEA 的官方 Android 应用开发集成开发环境 (IDE)。除了 IntelliJ 强大的代码编辑器和开发者工具,Android Studio 提供了更多可提高 Android 应用构建效率的功能,例如:

基于 Gradle 的灵活构建系统

快速且功能丰富的模拟器

可针对所有 Android 设备进行开发的统一环境

Instant Run,可将变更推送到正在运行的应用,无需构建新的 APK

可帮助您构建常用应用功能和导入示例代码的代码模板和 GitHub 集成

丰富的测试工具和框架

可捕捉性能、易用性、版本兼容性以及其他问题的 Lint 工具

C++ 和 NDK 支持

内置对 Google 云端平台的支持,可轻松集成 Google Cloud Messaging 和 App 引擎

2、Android JDK配置

3、Android Gradle配置

4、Android API配置

5、项目依赖配置

二、项目细节详情 1、andriodmanifest.xml配置详情 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.groundspace.lampmqtt"> <!-- Permissions the Application Requires --> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!--<uses-permission android:name="android.permission.READ_PHONE_STATE" />--> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:requestLegacyExternalStorage="true" android:screenOrientation="sensor" android:theme="@style/AppTheme"> <activity android:name="com.groundspace.lampmqtt.MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".BootBroadcastReceiver" android:enabled="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </receiver> <activity android:name=".Jieshou"/> <service android:name="org.eclipse.paho.android.service.MqttService"> </service> </application> </manifest> 2、ExampleInstrumentedTest配置详情 package com.groundspace.lampmqtt; import android.content.Context; import androidx.test.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; import static org.junit.Assert.assertEquals; /** * Instrumented test, which will execute on an Android device. * * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> */ @RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest { @Test public void useAppContext() { // Context of the app under test. Context appContext = InstrumentationRegistry.getTargetContext(); assertEquals("com.groundspace.lampmqtt", appContext.getPackageName()); } } 3、ExampleUnitTest配置详情 package com.groundspace.lampmqtt; import org.junit.Test; import static org.junit.Assert.*; /** * Example local unit test, which will execute on the development machine (host). * * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> */ class ExampleUnitTest { @Test public void addition_isCorrect() { assertEquals(4, 2 + 2); } } 4、Utils配置详情 package com.groundspace.lampmqtt; import javax.crypto.Mac; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; public class Utils { public static final String bytesToHexString(byte[] bArray) { StringBuffer sb = new StringBuffer(bArray.length); String sTemp; for (int i = 0; i < bArray.length; i++) { sTemp = Integer.toHexString(0xFF & bArray[i]); if (sTemp.length() < 2) { sb.append(0); } sb.append(sTemp.toUpperCase()); } return sb.toString(); } public static String encryptHMAC(String signMethod, String content, String key) throws Exception { SecretKey secretKey = new SecretKeySpec(key.getBytes("utf-8"), signMethod); Mac mac = Mac.getInstance(secretKey.getAlgorithm()); mac.init(secretKey); byte[] data = mac.doFinal(content.getBytes("utf-8")); return bytesToHexString(data); } } 5、activity_main.xml配置详情 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@mipmap/beijing" tools:context=".MainActivity" android:orientation="vertical"> <LinearLayout android:singleLine="true" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingLeft="120dp" android:paddingTop="85dp"> <ImageView android:layout_width="200dp" android:layout_height="80dp" android:src="@drawable/yaoquan" android:gravity="left" /> </LinearLayout> <LinearLayout android:singleLine="true" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingLeft="380dp" android:paddingTop="200dp"> <Button android:id="@+id/fh1" android:layout_width="200dp" android:layout_height="80dp" android:text="进入系统" android:textSize="35dp"/> </LinearLayout> <ScrollView android:id="@+id/scrollView2" android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> </LinearLayout> </ScrollView> </LinearLayout> 6、Gradle Scripts配置详情 build.gradle(Project) // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:4.1.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() maven { url "https://repo.eclipse.org/content/repositories/paho-snapshots/" } } } task clean(type: Delete) { delete rootProject.buildDir } build.gradle(Module) apply plugin: 'com.android.application' android { compileSdkVersion 31 defaultConfig { applicationId "com.groundspace.lampmqtt" minSdkVersion 14 targetSdkVersion 31 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } buildToolsVersion '30.0.0' } dependencies { implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0' implementation group: 'commons-codec', name: 'commons-codec', version: '1.11' implementation fileTree(dir: 'libs', include: ['*.jar']) //noinspection GradleCompatible implementation 'com.android.support:appcompat-v7:31.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1' implementation files('..\\jxl-2.6.12.jar') testImplementation 'junit:junit:4.13.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation files('../.idea/libraries/gson-2.7.jar') implementation files('../.idea/libraries/json.jar') }

设备入云,尽在帧通智能 设备入云和自动化解决方案咨询

总结

以上就是今天要讲的内容,本文仅仅简单介绍了Android Studio 4.1写设备APP的配置,而Android Studio 4.1提供了大量能使我们快速便捷地开发客户端的具体部署和方法。

相关文章

快速排序(C语言)

快速排序(C语言)...

第8期:云原生—— 大学生职场小白该如何学

第8期:云原生—— 大学生职场小白该如何学...

实验二.常用网络命令

实验二.常用网络命令...

手把手教你Linux的网络配置

手把手教你Linux的网络配置...

Elasticsearch RestHighLevelClient 已标记为被弃用 它的替代方案 Elasticsearch Java API Client 的基础教程及迁移方案

Elasticsearch RestHighLevelClient 已标记为被弃用 它的替代方案 Elasticsearch Java API Client 的基础教程及迁移方案...

【Linux】Linux下的常用命令汇总

【Linux】Linux下的常用命令汇总...