package com.example.notification;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.os.Build;
public class MainActivity extends Activity {
private TextView info=null;
private Handler handler=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
this.info=(TextView)super.findViewById(R.id.info);
getWebSource();
this.handler=new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
System.out.println("msg的大小事"+msg.what);
if(msg.what==0){
info.setText("服务器异常");
}else if(msg.what==1){
info.setText("登陆成功");
}
else{
info.setText("失败");
}
}
};
}
private void getWebSource(){
new Thread(new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
Message msg=new Message();
try {
URL url=new URL("http","192.168.1.50",8080,"/AndroidWebServices/index.jsp?name=ws&&password=12345");
HttpURLConnection conn=(HttpURLConnection)url.openConnection();
byte[] data=new byte[1024];
int len=conn.getInputStream().read(data);
String temp=new String(data,0,len);
System.out.println("服务器的内容是"+temp);
if(len>0){
msg.what=1;
handler.sendMessage(msg);
}
conn.getInputStream().close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
msg.what=0;
handler.sendMessage(msg);
}
}
}).start();;
}
}
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.os.Build;
public class MainActivity extends Activity {
private TextView info=null;
private Handler handler=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
this.info=(TextView)super.findViewById(R.id.info);
getWebSource();
this.handler=new Handler(){
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
System.out.println("msg的大小事"+msg.what);
if(msg.what==0){
info.setText("服务器异常");
}else if(msg.what==1){
info.setText("登陆成功");
}
else{
info.setText("失败");
}
}
};
}
private void getWebSource(){
new Thread(new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
Message msg=new Message();
try {
URL url=new URL("http","192.168.1.50",8080,"/AndroidWebServices/index.jsp?name=ws&&password=12345");
HttpURLConnection conn=(HttpURLConnection)url.openConnection();
byte[] data=new byte[1024];
int len=conn.getInputStream().read(data);
String temp=new String(data,0,len);
System.out.println("服务器的内容是"+temp);
if(len>0){
msg.what=1;
handler.sendMessage(msg);
}
conn.getInputStream().close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
msg.what=0;
handler.sendMessage(msg);
}
}
}).start();;
}
}