ImageVerifierCode 换一换
格式:DOCX , 页数:87 ,大小:117.47KB ,
资源ID:20950634      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/20950634.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(android常用的代码 直接复制粘贴可用Word文档格式.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

android常用的代码 直接复制粘贴可用Word文档格式.docx

1、 if (fos != null) try fos.flush(); fos.close(); catch (IOException e) / TODO: handle exception 2.下载图片工具publicclassDownloadPicUtil /*paramurl*paramfilename*return0没有图片;return1成功;return2IO异常;*/ publicstaticintDownLoadBitmap(String url,Stringfilename) / TODO Auto-generated method stub InputStream input

2、Stream= null; DefaultHttpClient client = newDefaultHttpClient(); HttpGet request=newHttpGet(url); HttpResponse response=client.execute(request); int statusCode = response.getStatusLine().getStatusCode(); if(statusCode!=HttpStatus.SC_OK) return 0; else HttpEntity entity =response.getEntity(); inputSt

3、ream = entity.getContent(); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); /图片可以在这个时候存储到sdcard上 saveBitmap(bitmap,filename); return 1; catch (Exception e) return 2; finally if(inputStream!=null) inputStream.close(); / TODO Auto-generated catch block e.printStackTrace(); publicstaticvoidsav

4、eBitmap(Bitmap bitName,String filename) String filepath = /sdcard/baomi/; File f = newFile(filepath+filename); FileOutputStream fout = null; try f.createNewFile(); fout = newFileOutputStream(f); bitNpress(Bitmap.CompressFormat.PNG,100,fout); fout.flush(); fout.close(); catch(Exception e)3.http请求工具pu

5、blicclassHttpUtil publicstaticStringSESSION_ID=null; publicstaticHttpResponsegetHttpResponse(HttpGet request) throws ClientProtocolException,IOException BasicHttpParams httpParams = newBasicHttpParams(); LogService.getInstance().recordLog(进入getHttpResponse); HttpConnectionParams.setConnectionTimeout

6、(httpParams, SysConfig.nConnectionTimeout);超时时间为:+SysConfig.nConnectionTimeout); HttpConnectionParams.setSoTimeout(httpParams, SysConfig.nSoTimeout);Socket超时时间为:+SysConfig.nSoTimeout); DefaultHttpClient httpClient = newDefaultHttpClient(httpParams);获得响应客户端 HttpResponse response=httpClient.execute(re

7、quest);获得结果 httpClient.getConnectionManager().shutdown();关闭连接 return response; publicstaticHttpResponsegetHttpResponse(HttpPost request) throws ClientProtocolException,IOException /通过url发送post请求,并返回结果 publicstaticStringqueryStringForPost(String url)发送POST请求 HttpPost request = newHttpPost(url); Strin

8、g result=null; HttpResponse response=HttpUtil.getHttpResponse(request); LogService.getInstance().recordLog(POST返回状态为+response.getStatusLine().getStatusCode(); if(response.getStatusLine().getStatusCode()=200) result=EntityUtils.toString(response.getEntity(); return result; catch (Exception e) POST异常:

9、+e.getMessage(); e.printStackTrace(); result=网络异常return result; returnnull; /通过url发送GET请求并返回结果 publicstaticStringqueryStringForGet(String url)发送GET请求 ResponseHandler responseHandler = newBasicResponseHandler(); HttpClient httpclient = newDefaultHttpClient();提交的地址为:+url); HttpGet httpget = newHttpGet

10、(url); result = httpclient.execute(httpget, responseHandler);GET返回状态为+result); return result;GET异常: /通过HttpPost发送POST请求,并返回结果 publicstaticStringqueryStringForPost(HttpPost request)4.JSon工具public class JSonUtil public static String string2json(String s) StringBuilder sb = new StringBuilder(s.length()

11、+20); sb.append( for (int i=0;is.length();i+) char c =s.charAt(i); switch(c) case : sb.append( break;/bbffnnrrtt default: sb.append(c); return sb.toString(); public static String number2json(Number number) return number.toString(); public static String boolean2json(Boolean bool) return bool.toString

12、(); public static String map2json(Map map) if(map.isEmpty() return StringBuilder sb = new StringBuilder(map.size()4); sb.append( Set keys = map.keySet(); for(String key :keys) Object value = map.get(key); sb.append( sb.append(key); sb.append( sb.append(tojson(value);, sb.setCharAt(sb.length()-1, pub

13、lic static String array2json(Object array) if(array.length=0) StringBuilder sb = new StringBuilder(array.length for(Object o:array) sb.append(tojson(o); public static String tojson(Object o) if(o=null)null if(o instanceof String) return string2json(String)o); if(o instanceof Boolean) return boolean2

14、json(Boolean)o); if(o instanceof Number) return number2json(Number)o); if(o instanceof Map) return map2json(Map)o); if(o instanceof Object) return array2json(Object)o); throw new RuntimeException(Unsupported type :+o.getClass().getName(); /*Servlet 输出json response.setContentType(application/json;cha

15、rset=UTF-8 response.setCharacterEncoding(UTF-8 PrintWriter pw = response.getWriter(); pw.write(JSonUtil.tojson(obj); pw.flush(); */5.Stirng encode 转ucs2码双字节publicclassStringUtil publicstaticStringStringToHex(String input) String result = if (input ! byte bytes = null; try bytes = input.getBytes(UTF-

16、16BE catch (Exception e) / TODO Auto-generated catch block returnnull; StringBuffer reValue = newStringBuffer(); StringBuffer tem = newStringBuffer(); for (int i = 0; i bytes.length; i+) tem.delete(0, tem.length(); tem.append(Integer.toHexString(bytesi & 0xFF); if (tem.length() = 1) tem.insert(0, 0

17、reValue.append(tem); result = reValue.toString().toUpperCase(); else return publicstaticStringHexToUTF16BE(String input) Stringresult = byte bytes1 = newbyteinput.length() / 2; input.length(); i += 2) bytes1i / 2 = (byte) (Integer.parseInt(input.substring(i, i + 2), 16); result = newString(bytes1, c

18、atch (UnsupportedEncodingException e) return null; return 6.Notification实例NotificationManager notificationManager=(NotificationManager)context.getSystemService(NOTIFICATION_SERVICE); /定义一个Notification Notification m_notification = newNotification(); /设置Notification的各种属性 /设置通知在状态栏的图标 m_notification.i

19、con = R.drawable.icon; /当我们点击通知时显示的内容 m_notification.tickerText = BUTTON1通知内容 /通知时发出的默认声音 m_notification.defaults = Notification.DEFAULT_SOUND; /设置通知显示的参数 Intent intent = newIntent(); PendingIntent m_pendingIntent = PendingIntent.getActivity(testNotification.this,0,intent,0); m_notification.setLatestEventInfo(testNotification.this,BUTTON,m_pendingIntent); /开始执行通知 i+; notificationManager.notify(i,m_notification);7.POSTURL TheardpublicclassPostThreadextendsThread privatestaticContextcontex

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1