温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android中怎么访问Internet

发布时间:2021-07-20 14:59:04 来源:亿速云 阅读:122 作者:Leah 栏目:移动开发

今天就跟大家聊聊有关Android中怎么访问Internet,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

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

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

然后实现DrawMap()如下:

private void drawMap(){  try{      graphics2D.clear(Color.WHITE);  graphics2D.Reset();  for(int x=6;x<8;x++)  {  for(int y=3;y<5;y++){  String urlString="http://www.mapdigit.com/guidebeemap";  urlString+="/maptile.php?type=MICROSOFTMAP";  urlString+="&x="+x+"&y="+y+"&z=14";  URL url=new URL(urlString);  URLConnection connection=url.openConnection();  HttpURLConnection httpConnection=(HttpURLConnection)connection;  int responseCode=httpConnection.getResponseCode();  if(responseCode==HttpURLConnection.HTTP_OK){  InputStream stream=httpConnection.getInputStream();  Bitmap bitmap=BitmapFactory.decodeStream(stream);  int []buffer=new int[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(Exception e){      } }

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

Android中怎么访问Internet

看完上述内容,你们对Android中怎么访问Internet有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI