Android app与PC端交互
app提交信息到PC端mysql数据库
新建名为SignActivity
package com.example.administrator.success; import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText; public class SignActivity extends Activity {
private EditText name;
// private EditText password;
private Button signup;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign);
name=(EditText) findViewById(R.id.etSgAccount);
// password=(EditText) findViewById(R.id.etSgPassword);
signup=(Button) findViewById(R.id.btnSign);
}
/*发起HTTP请求*/
public void onLogin(View v)
{
String url="http://182.92.66.60:8083/saveTestApp.jsp";
new HttpThread(url, name.getText().toString()).start();
} }
HttpThread
package com.example.administrator.success; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL; import android.R.string; public class HttpThread extends Thread {
String url;
String name;
// String password; public HttpThread(String url, String name) {
// TODO Auto-generated constructor stub
this.url = url;
this.name = name;
// this.password = password;
} private void doGet() throws IOException {
/*将username和password传给Tomcat服务器*/
url=url+"?name="+name;
try {
URL httpUrl = new URL(url);
/*获取网络连接*/
HttpURLConnection conn = (HttpURLConnection) httpUrl.openConnection();
/*设置请求方法为GET方法*/
conn.setRequestMethod("GET");
/*设置访问超时时间*/
conn.setReadTimeout(5000);
BufferedReader reader=new BufferedReader(new InputStreamReader(conn.getInputStream()));
String str;
StringBuffer sb=new StringBuffer();
//读取服务器返回的信息
while((str=reader.readLine())!=null)
{
sb.append(str);
}
//把服务端返回的数据打印出来
System.out.println("result"+sb.toString());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} } /*在run中调用doGet*/
@Override
public void run() {
try {
doGet();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
布局文件activity_sign.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:background="#ff6699cc"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fffffffb"
android:orientation="horizontal"
android:padding="40dp" > <EditText
android:id="@+id/etSgAccount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginBottom="20dp"
android:hint="Account"
android:inputType="textEmailAddress" /> <EditText
android:id="@+id/etSgPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/etSgAccount"
android:layout_marginBottom="20dp"
android:hint="Password"
android:inputType="textPassword" />
<EditText
android:id="@+id/etSgRePassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/etSgPassword"
android:layout_marginBottom="20dp"
android:hint="repassword"
android:inputType="textPassword" /> <Button
android:id="@+id/btnSign"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/etSgRePassword"
android:background="#ff6699cc"
android:onClick="onLogin"
android:text="signup"
android:textColor="#ffffffff"
android:textSize="24sp" />
</RelativeLayout> </LinearLayout>
自己搭一个Tomact服务器,把SignActivity里的url换成自己的就OK了
Android app与PC端交互的更多相关文章
- Android客户端与服务端交互之登陆示例
Android客户端与服务端交互之登陆示例 今天了解了一下android客户端与服务端是怎样交互的,发现其实跟web有点类似吧,然后网上找了大神的登陆示例,是基于IntentService的 1.后台 ...
- 我的Android进阶之旅------>Android实现用Android手机控制PC端的关机和重启的功能(三)Android客户端功能实现
我的Android进阶之旅------>Android实现用Android手机控制PC端的关机和重启的功能(一)PC服务器端(地址:http://blog.csdn.net/ouyang_pen ...
- android中的HttpURLConnection和HttpClient实现app与pc数据交互
自学android的这几天很辛苦,但是很满足,因为每当学到一点点知识点都会觉得很开心,觉得今天是特别有意义的,可能这个就是一种莫名的热爱吧. 下面来说说今天学习的HttpURLConnection和H ...
- android客户端app和服务端交互token的作用
Android客户端和服务端如何使用Token和Session niceheart关注1人评论34644人阅读2014-09-16 16:38:44 对于初学者来说,对Token和Session的 ...
- JS判断android ios系统 PC端和移动端
最近公司上线移动端,需要根据不同的系统跳转到不同的产品页面,百度后发现这一段代码很好用,不但可以判断当前是什么系统,还能知道当前浏览器是什么内核,移动端PC端都已测试无问题! var browser ...
- 我的Android进阶之旅------>Android实现用Android手机控制PC端的关机和重新启动的功能(二)Androidclient功能展示
Androidclient的实现思路大致例如以下: 1.首先扫描局域网内全部PC,看是否有PC端的server在执行并监听30000port. watermark/2/text/aHR0cDovL2J ...
- Android App之间通过Intent交互
Android 最重要的功能之一是应用能够基于它要执行的"操作"向另一个应用发送用户. 例如,如果您的应用有您要在地图上显示的公司地址,您无需在显示地图的应用中构建 Activit ...
- PC/APP/H5三端测试的相同与不同
随着手机应用的不断状态,同一款产品的移动端应用市场占相较PC端也越来越大,那么app与PC端针对这些产品的测试有什么相同与不同之处呢?总结如下: 首先谈一谈相同之处: 一,针对同一个系统功能的测试,三 ...
- Android App常规测试内容
转自:https://mp.weixin.qq.com/s?__biz=MzU0NjcyNDg3Mw==&mid=2247484053&idx=1&sn=116fe8c7eed ...
随机推荐
- hdu4930 Fighting the Landlords(模拟 多校6)
题目链接:pid=4930">http://acm.hdu.edu.cn/showproblem.php? pid=4930 Fighting the Landlords Time L ...
- 【Shell】Read命令
read命令从键盘读取变量的值,通常用在shell脚本与用户进行交互的场合.该命令可以一次性读取多个变量的值,变量的输入和输出需要使用空格隔开.在read命令后面,如果没有指定变量名,读取的数据将被自 ...
- textarea字数限制方法一例
<!-- 控制textarea最大输入字数 --><script type="text/javascript">function checkLen(obj) ...
- 关系型数据的分布式处理系统MyCAT(转载)
——概述和基本使用教程 日期:2014/12/24 文:阿蜜果 1. MyCAT概述 1.1 背景 随着传统的数据库技术日趋成熟.计算机网络技术的飞速发展和应用范围的扩充,数据库应用已经普遍建 ...
- Java种八种常用排序算法
1 直接插入排序 经常碰到这样一类排序问题:把新的数据插入到已经排好的数据列中. 将第一个数和第二个数排序,然后构成一个有序序列 将第三个数插入进去,构成一个新的有序序列. 对第四个数.第五个数……直 ...
- C#中执行存储过程并在SQL server中调试
1.编写存储过程 ) drop PROCEDURE [dbo].[sp_calcPci_of_baseRcd_GTmpTbl] CREATE PROCEDURE [dbo].[sp_calcPci_o ...
- POJ1328 Radar Installation 【贪心·区间选点】
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 54593 Accepted: 12 ...
- different between method and function
A method is on an object. A function is independent of an object. For Java, there are only methods. ...
- 笔记本中G-Sensor(加速计) M-Sensor 陀螺仪等传感器的区别与作用
1.G-sensor重力传感器 作用 G-sensor中文是加速度传感器的意思(英文全称是Accelerometer-sensor),它能够感知到加速力的变化,加速力就是当物体在加速过程中作用在物体上 ...
- CCKiller:Linux轻量级CC攻击防御工具,秒级检查、自动拉黑和释放 《CCKiller:Linux轻量级CC攻击防御工具,秒级检查、自动拉黑和释放》来自张戈博客
张戈博客很久以前分享过一个CC攻击的防御脚本,写得不怎么样,不过被51CTO意外转载了.博客从此走上了经常被人拿来练手的不归之路. 当然,还是有不少朋友在生产环境使用,并且会留言询问相关问题.根据这些 ...