Android Get方式发送信息
程序需要用到Internet权限,所以需要在AndroidManifest.xml添加
<uses-permission android:name="android.permission.INTERNET"/>
MainActivity.java
public class MainActivity extends Activity {
private TextView info=null;
private Button Btn01=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.activity_main);
this.info=(TextView)super.findViewById(R.id.info);
this.Btn01=(Button)super.findViewById(R.id.Btn01);
this.Btn01.setOnClickListener(new OnClickListenerImpl());
}
private class OnClickListenerImpl implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println(">>Button");
switch (v.getId()) {
case R.id.Btn01:
try {
System.out.println(">>btn01");
//URL url=new URL("http","172.17.8.28",80,"android.ashx");
URL url=new URL("http","t.sina.com",80,"/");
HttpURLConnection conn=(HttpURLConnection)url.openConnection();
byte data[]= new byte[512];
int len=conn.getInputStream().read(data);//输入流读取
System.out.println(">>len="+len);
if(len>0){
String temp= new String(data,0,len).trim();
//flag=Boolean.parseBoolean(temp); //取出里面的bool数据
System.out.println(">>"+temp);
MainActivity.this.info.setText(temp);
}
conn.getInputStream().close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Error:"+e.toString());
}
break;
default:
break;
}
}
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<Button
android:id="@+id/Btn01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="测试" />
<TextView
android:id="@+id/info"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> </LinearLayout>
Android Get方式发送信息的更多相关文章
- Android Post方式发送信息和获取URL中的图片
需要Internet权限,AndroidManifest.xml <uses-permission android:name="android.permission.INTERNET& ...
- 在android用Get方式发送http请求
烦人的日子终于过去啦,终于又可以写博客啦,对自己的android学习做个总结,方便以后查看...... 一.在android用Get方式发送http请求,使用的是java标准类,也比较简单. 主要分以 ...
- Android - 向服务器发送数据(POST) - HTTPClient.
该篇文章主要说明使用Apache提供的HTTPClient,通过post方式,向服务器发送数据.由于有些东西在 Android - 向服务器发送数据(GET)中提到过,就不再重复. 一,Android ...
- Android应用程序发送广播(sendBroadcast)的过程分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6744448 前面我们分析了Android应用程 ...
- Android HTTP实例 发送请求和接收响应
Android HTTP实例 发送请求和接收响应 Android Http连接 实例:发送请求和接收响应 添加权限 首先要在manifest中加上访问网络的权限: <manifest ... & ...
- wireshake抓包,飞秋发送信息,python
http://wenku.baidu.com/link?url=Xze_JY8T15pqI9mBLRpTxWF2d6MP-32xb6UwuE6tsUmitRDheJe-Ju87WlDEDBGuI5MF ...
- android之读取联系人信息
联系人信息被存放在一个contacts2.db的数据库中 主要的两张表 读取联系人 读取联系人需要知道联系人内容提供者的地址,以及对应的操作对象.一般情况下操作对象是的命名方式和表明是一致的. 布局文 ...
- C#带cookie Post和Get方式发送数据,保持cookie
在实际编程中,可能需要读取特定网页的信息,但很多网站需要用户登录后,才能够获取相关的页面内容,这就需要编程者先临时存储当前的cookie,在C#中可以使用CookieContainer 对象来保存登录 ...
- android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序
android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序 在应用里使用了后台服务,并且在通知栏推送了消息,希望点击这个消息回到activity ...
随机推荐
- postman的使用方法详解
Collections:在Postman中,Collection类似文件夹,可以把同一个项目的请求放在一个Collection里方便管理和分享,Collection里面也可以再建文件夹.如果做API文 ...
- mybatis mysql 批量insert 返回主键
Mybatis在插入单条数据的时候有两种方式返回自增主键: mybatis3.3.1支持批量插入后返回主键ID, 首先对于支持自增主键的数据库:useGenerateKeys和keyProper ...
- Linux常用命令----基本文件系统常用命令
1.查看当前工作目录---pwd sunny@sunny-ThinkPad-T450:~$ pwd /home/sunny sunny@sunny-ThinkPad-T450:~$ cd Worksp ...
- C#中的goto
int i = 9;if (i % 2 == 0) goto Found;else goto NoFound; NoFound: Console.WriteLine(i.ToSt ...
- svn与eclipse的集成(第三方插件与eclipse的集成)
在eclipse中点击Help,选中install from site..
- FP回写报错
报错信息如下: 提示java for mo 2022报错 执行的DTS如下: 解决方法:(原因:SAP归档日志满了,导致连接失败)1.检查表temp_out_pr中的siteid是否有三个工厂的数据确 ...
- Quaternion.identity是什么意思?
Quaternion.identity就是指Quaternion(0,0,0,0),
- 这几天搞UNITY遇到的坑
都是在IPHONE设备上遇到的,UNITY版本是5.4.4f1 1.EASY AR出现扫描蓝线绿块的,是因为不是EASY AR的CameraDeviceBehavior默认参数1280X720 2.自 ...
- pthread_mutex_init函数与pthread_mutexattr_init函数
直接上英文解释: pthread_mutex_init()如下: NAME pthread_mutex_init, pthread_mutex_destroy - initialise or dest ...
- Fix: The account is not authorized to log in from this station
If you have more the one computers running Windows, then its possible to connect them using HomeGrou ...