Android客户端与后台服务器的数据交互

Android客户端与服务器的数据交互

  这是今年7月份时在一家公司实训时自己做的一个小项目,仅仅是一个简单的模拟Android客户端与服务器的数据交互,中间会有串口通信,以及利用JDBC连接Mysql数据库的相关代码。其中网络通信采用的是HTTP协议,串口通信使用的是开源RXTX包实现。

  Android客户端:
  1. 登录界面:                                      
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        style="@style/AppTheme"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/t1"
        android:gravity="center_vertical"
        android:orientation="vertical"
        tools:context="${relativePackage}.${activityClass}" >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
    
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:layout_weight="1"
                android:text="@string/UserName"
                android:textColor="#00ffff"
                android:textColorHighlight="#00ffff"
                style="@style/AppTheme"
                android:textSize="20sp" />
    
            <EditText
                android:id="@+id/Username"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="3"
                android:textColor="#ffffff"
                android:textColorHighlight="#00ffff"
                android:inputType="text" />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
    
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:layout_weight="1"
                android:text="@string/Password"
                android:textColor="#00ffff"
                android:textColorHighlight="#00ffff"
                android:textSize="20sp" />
    
            <EditText
                android:id="@+id/Password"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="3"
                android:inputType="textPassword"
                android:textColor="#ffffff"
                android:textColorHighlight="#00ffff" />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dp"
            android:gravity="center_horizontal"
            android:orientation="horizontal" >
    
            <Button
                android:id="@+id/btn_Login"
                style="@style/AppTheme"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/Login"
                android:textColor="#d9d919"
                android:textSize="20sp" />
    
            <Button
                android:id="@+id/btn_Reset"
                style="@style/AppTheme"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/Reset"
                android:textColor="#d9d919"
                android:textSize="20sp" />
        </LinearLayout>
    
    </LinearLayout>
  2. 在开始业务逻辑之前先加上访问网络的授权:
     <uses-permission android:name="android.permission.INTERNET" />

  3. 登录业务代码:
    package com.zhou.android;
    
    import java.lang.ref.WeakReference;
    
    import com.zh
  • 16
    点赞
  • 115
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值