Android中怎么访问Internet(android,internet,移动开发)

时间:2024-05-09 11:48:31 作者 : 石家庄SEO 分类 : 移动开发
  • TAG :

Android应用访问Internet,首先需要赋予应用有访问Internet的权限:在AndroidManifest.xml中添加:

<uses-permissionandroid:name=”android.permission.INTERNET”/>

然后实现DrawMap()如下:

privatevoiddrawMap(){try{graphics2D.clear(Color.WHITE);graphics2D.Reset();for(intx=6;x<8;x++){for(inty=3;y<5;y++){StringurlString="http://www.mapdigit.com/guidebeemap";urlString+="/maptile.php?type=MICROSOFTMAP";urlString+="&x="+x+"&y="+y+"&z=14";URLurl=newURL(urlString);URLConnectionconnection=url.openConnection();HttpURLConnectionhttpConnection=(HttpURLConnection)connection;intresponseCode=httpConnection.getResponseCode();if(responseCode==HttpURLConnection.HTTP_OK){InputStreamstream=httpConnection.getInputStream();Bitmapbitmap=BitmapFactory.decodeStream(stream);int[]buffer=newint[bitmap.getHeight()*bitmap.getWidth()];bitmap.getPixels(buffer,0,bitmap.getWidth(),0,0,bitmap.getWidth(),bitmap.getHeight());graphics2D.drawImage(buffer,bitmap.getWidth(),bitmap.getHeight(),(x-6)*256,(y-3)*256);}}}graphic2dView.refreshCanvas();}catch(Exceptione){}}

Android中访问Internet类主要定义在java.net.* 和android.net.*包中。上面显示结果如下:

Android中怎么访问Internet

 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:Android中怎么访问Internet的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:Android中怎么自定义对话框下一篇:

10 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18