当前位置: 首页 > news >正文

网站之前没备案深圳高端网站设计

网站之前没备案,深圳高端网站设计,微信网站主题,网站排名下降原因好久没有写东西了。备份下知识吧。免得忘记了 。 首先贴一段代码 #xff0d;#xff0d; 这个是先生成一个本地的路径#xff0c;将图片保存到这个文件中#xff0c;然后扫描下sd卡。让系统相册重新加载下 。缺点就是只能保存到DCIM的文 件夹下边#xff0c;暂时不知道怎…好久没有写东西了。备份下知识吧。免得忘记了 。 首先贴一段代码  这个是先生成一个本地的路径将图片保存到这个文件中然后扫描下sd卡。让系统相册重新加载下 。缺点就是只能保存到DCIM的文 件夹下边暂时不知道怎么获取系统相机的路径网上找了下说了好几个方法。其中有一条就是去读取本地的图片然后根据一定的规则识别出本地相册的路径 保存下不过觉得性能不是很好。谁有更好的方法可以提供下。   private class DownloadTask extends AsyncTaskString, Integer, String {private Context context;private String filepath;public int fileLength 0; public DownloadTask(Context context) {this.context context;File cacheDir new File(ImageLoader.getExternalCacheDir(context).getAbsolutePath() );if(!cacheDir.exists()) {cacheDir.mkdirs();} // filepath ImageLoader.getExternalCacheDir(context).getAbsolutePath() File.separator caihongjiayuan.jpg;filepath UIUtils.generateDownloadPhotoPath();}SuppressWarnings(resource)Overrideprotected String doInBackground(String... sUrl) {PowerManager pm (PowerManager) context.getSystemService(Context.POWER_SERVICE);PowerManager.WakeLock wl pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());wl.acquire();InputStream input null;OutputStream output null;HttpURLConnection connection null;try {URL url new URL(sUrl[0]);connection (HttpURLConnection) url.openConnection();connection.setConnectTimeout(5000);connection.setReadTimeout(20000);connection.connect();// expect HTTP 200 OK, so we dont mistakenly save error report// instead of the fileif (connection.getResponseCode() ! HttpURLConnection.HTTP_OK)return Server returned HTTP connection.getResponseCode() connection.getResponseMessage();fileLength connection.getContentLength();input connection.getInputStream();output new FileOutputStream(filepath);byte data[] new byte[4096];long total 0;int count;while ((count input.read(data)) ! -1) {// allow canceling with back buttonif (isCancelled())return null;total count;if (fileLength 0) // only if total length is knownpublishProgress((int)total);output.write(data, 0, count);}} catch (Exception e) {return null;} finally {try {if (output ! null)output.close();if (input ! null)input.close();} catch (IOException ignored) {}if (connection ! null)connection.disconnect();wl.release();}return filepath;}Overrideprotected void onProgressUpdate(Integer... values) {// TODO Auto-generated method stubsuper.onProgressUpdate(values);float progress (float)values[0]/(float)fileLength;mProgressInfo.setText(getString(R.string.download_progress_info,StringUtils.getKBUnitString(values[0]),StringUtils.getKBUnitString(fileLength)));mProgressBar.setProgress((int)(progress * 100));}Overrideprotected void onPostExecute(String result) {// TODO Auto-generated method stubsuper.onPostExecute(result);mDownloadView.setVisibility(View.GONE);if (!TextUtils.isEmpty(result)) {ImageUtils.scanFile(mCurrentActivity, filepath);ToastUtils.showLongToast(mCurrentActivity, mCurrentActivity.getString(R.string.tips_img_save_path, filepath));}else {ToastUtils.showLongToast(mCurrentActivity, R.string.tips_download_photo_faile);}// // Bitmap bitmap BitmapFactory.decodeFile(filepath); // boolean flag ImageUtils.insertImageToAllbum(bitmap, mCurrentActivity); // if (flag) {ToastUtils.showLongToast(mCurrentActivity, R.string.tips_download_photo_success); // }else { // ToastUtils.showLongToast(mCurrentActivity, R.string.tips_download_photo_faile); // }}}参考了下别的文章找到下边一个方法能解决大部分机型适配的问题且可以将照片保存到系统相机拍完照的目录下。供大家参考。 private class DownloadTask extends AsyncTaskString, Integer, Boolean {private Context context;public int fileLength 0;private Bitmap bmp; public DownloadTask(Context context) {this.context context;File cacheDir new File(ImageLoader.getExternalCacheDir(context).getAbsolutePath() );if(!cacheDir.exists()) {cacheDir.mkdirs();}}SuppressWarnings(resource)Overrideprotected Boolean doInBackground(String... sUrl) {PowerManager pm (PowerManager) context.getSystemService(Context.POWER_SERVICE);PowerManager.WakeLock wl pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());wl.acquire();InputStream input null;ByteArrayOutputStream output null;HttpURLConnection connection null;try {URL url new URL(sUrl[0]);connection (HttpURLConnection) url.openConnection();connection.setConnectTimeout(5000);connection.setReadTimeout(20000);connection.connect();// expect HTTP 200 OK, so we dont mistakenly save error report// instead of the fileif (connection.getResponseCode() ! HttpURLConnection.HTTP_OK)return false;fileLength connection.getContentLength();input connection.getInputStream();output new ByteArrayOutputStream();byte data[] new byte[4096];long total 0;int count;while ((count input.read(data)) ! -1) {// allow canceling with back buttonif (isCancelled())return false;total count;if (fileLength 0) // only if total length is knownpublishProgress((int)total);output.write(data, 0, count);}bmp BitmapFactory.decodeByteArray(output.toByteArray(),0 , output.toByteArray().length);return true;} catch (Exception e) {return false;} finally {try {if (output ! null)output.close();if (input ! null)input.close();} catch (IOException ignored) {}if (connection ! null)connection.disconnect();wl.release();}}Overrideprotected void onProgressUpdate(Integer... values) {// TODO Auto-generated method stubsuper.onProgressUpdate(values);float progress (float)values[0]/(float)fileLength;mProgressInfo.setText(getString(R.string.download_progress_info,StringUtils.getKBUnitString(values[0]),StringUtils.getKBUnitString(fileLength)));mProgressBar.setProgress((int)(progress * 100));}Overrideprotected void onPostExecute(Boolean result) {// TODO Auto-generated method stubsuper.onPostExecute(result);mDownloadView.setVisibility(View.GONE);if (result.booleanValue() ImageUtils.insertImageToAllbum(bmp, mCurrentActivity)) {}else {ToastUtils.showLongToast(mCurrentActivity, R.string.tips_download_photo_faile);}}} 两个方法的区别就是将FileOutputStream换成了ByteArrayOutputStream项目中主要是有显示下载进度条的需求所以稍微复杂了点。 另外 ImageUtils 中insertImage 方法如下。 public static boolean insertImageToAllbum(Bitmap bitmap,Context mContext) {if (bitmap ! null) {String uri MediaStore.Images.Media.insertImage(mContext.getContentResolver(),bitmap, , );if (!TextUtils.isEmpty(uri)) {String filePath getRealPathFromURI(Uri.parse(uri),mContext);ToastUtils.showLongToast(mContext, mContext.getString(R.string.tips_img_save_path, filePath));scanFile(mContext,filePath);return true;}}return false;}public static void scanFile(Context mContext,String path){MediaScannerConnection.scanFile(mContext, new String[] { path }, null,new MediaScannerConnection.OnScanCompletedListener() {public void onScanCompleted(String path, Uri uri) {}});}方法scanFile是让系统重新加载SD卡的 。。    over有疑问请留言欢迎指正错误。  转载于:https://www.cnblogs.com/gengsy/p/3905023.html
http://www.pierceye.com/news/646514/

相关文章:

  • 建设部网站人员查询商城网站 没有什么文章 怎样优化
  • wordpress按标签筛选广州seo网站
  • 南宁手机建站公司常德网站开发服务
  • 智能锁东莞网站建设php网站开发需要学什么软件
  • 扒网站样式中国搜索网站排名
  • 网站空间和云服务器建设建材网站费用
  • 公司网站 正式上线wordpress 移动端不显示
  • 旅行网站排名前十名网站检测报告哪里做
  • 随州做网站wordpress 显示评论内容
  • 网站建设时间计划表非常赚又一个wordpress站点
  • 苏州网站小程序app开发公司wordpress如何上传文件大小
  • 同仁行业网站建设报价免费ui网站
  • 网站打开速度慢wordpress开发者选项怎么打开
  • 免费网站代理访问网站 营销型
  • 甘特图模板关于网站建设永嘉移动网站建设公司
  • 网站建设服务协议书做面包有哪些网站知乎
  • 网站建设评比标准建盏茶杯知识
  • 商城网站建设教学电子商务的就业方向
  • 做网站必要性江苏华江建设集团网站
  • 网站建设丿金手指排名9如何百度搜到网站
  • 南昌商城网站建设央企网站群建设中标公告
  • 湖北建设监理协会网站网页游戏排行榜开服时间
  • 中国空间站图片竞价账户托管公司哪家好
  • 湖南省金力电力建设有限公司 网站广州市建设局官方网站
  • 比价网站源码免费域名领取
  • 温州做网站费用怎么推广自己的偏方
  • 鞍山建站wordpress侧边浮动
  • 江西网站优化临海外发加工网
  • 机械做网站好处无锡网络推广服务
  • 电信网站备案管理系统外贸网站推广的方法