|
本帖最后由 pz_cloud 于 2013-11-13 00:45 编辑
如下代码。。。非常简短,研究了很多遍觉得应该没有问题的啊。。作用是按一下button获得一张照片,再更新到imageview控件上,权限也设置过了,程序可以运行但是就是不起任何作用,收不到图片。。。望高手解答,感激不尽
public class HanryActivity extends Activity {
/* Called when the activity is first created. */
TextView t;
URL videoUrl;
Bitmap bmp;
public static String CameraIp;
private String url= "http://192.168.2.1:8080/?action=snapshot";
HttpURLConnection conn;
private ImageView im=null;
Button b =null;
Buttonlistener a=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
im = (ImageView) findViewById(R.id.im);
a= new Buttonlistener();
b = (Button)findViewById(R.id.button1);
b.setOnClickListener(a);
url = "http://192.168.2.1:8080/?action=snapshot";
try {
InputStream inputstream;
inputstream = null;
videoUrl = new URL(url);
conn = (HttpURLConnection) videoUrl.openConnection();
conn.setDoInput(true);
conn.connect();
inputstream = conn.getInputStream();
bmp = BitmapFactory.decodeStream(inputstream);
im.setImageBitmap(bmp);
conn.disconnect();
} catch (Exception ex) {
}
}
class Buttonlistener implements OnClickListener{
@Override
public void onClick(View v) {
// TODO 自动生成的方法存根
try {
InputStream inputstream;
inputstream = null;
videoUrl = new URL(url);
conn = (HttpURLConnection) videoUrl.openConnection();
conn.setDoInput(true);
conn.connect();
inputstream = conn.getInputStream();
bmp = BitmapFactory.decodeStream(inputstream);
im.setImageBitmap(bmp);
conn.disconnect();
im.setImageBitmap(bmp);
} catch (Exception ex) {
}
}
}
}
|
|