Bitmap bitmap;
//全局变量
Handler handler = new Handler() {
public void handleMessage(android.os.Message msg) {
if (msg.what ==
123) {
// 将获取到的图片显示到控件上面
imageView0.setImageBitmap(bitmap);
}
};
};
// 开启线程
new Thread() {
public void run() {
try {
// 实例化URL对象
URL url = new URL(
//计算机本地 IP地址 ipconfig查看本机IP地址
// 建立链接
HttpURLConnection conn = (HttpURLConnection) url
.openConnection();
// 获取输入流对象
InputStream is = conn.getInputStream();
// 将流转化成Bitmap对象
bitmap = BitmapFactory.decodeStream(is);
// 发送一个空消息
handler.sendEmptyMessage(
123);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
}.start();
----------------------------------------------------------------------------------------------------------------
访问网页跳转到浏览器:
new Thread() {
public void run() {
try {
Uri uri = Uri.parse("
http://192.168.43.74:50551/");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//handler.sendEmptyMessage(0);
};