2019独角兽企业重金招聘Python工程师标准>>>

不用reboot就可以让数据出现的方法.

As anyone who worked with android applications experienced, the files created by Android application in “External Storage” (I don’t like this term, as this usually refers to internal memory of the device), do not show up in windows explorer until the device is rebooted.

Initially we used recording to external media (USB drives, SD Cards) as a workaround. However, some smart guy working on Android added a “feature” since Honeycomb 3.2 , that made the external storage effectively write-protected for non-system applications. Since that avenue is closed, we are forced to record stuff to storage available on the device itself.

Storing stuff on the device poses a few challenges. One of them is copying those files to a PC. One strange behaviour we noticed was, if we just created the files from the application and then plug the tablet to PC, the files we have just created do not show up in windows explorer. However once you reboot the device, the files show up as usual.

I found that, for the MTP protocol to present the file to windows, the service should be aware of the file. When a device reboots, the MediaScanner scans the storage volumes and indexes all the files. However files created once the scan is complete are not automatically added to the index. I found an efficient way (for me) to add a single file to index without forcing a media scan of the whole drive.

importandroid.media.MediaScannerConnection;
importandroid.media.MediaScannerConnection.MediaScannerConnectionClient;publicclassMediaScannerHelperimplementsMediaScannerConnectionClient {publicvoidaddFile(String filename)</pre>{String [] paths =newString[1];paths[0] = filename;MediaScannerConnection.scanFile(context, paths,null,this);}publicvoidonMediaScannerConnected() {}publicvoidonScanCompleted(String path, Uri uri) {Log.i("ScannerHelper","Scan done - path:"+ path +" uri:"+ uri);}
}

Once writing to a file is done and I close the FileOutputStream and call the addFile() method with the absolute file name. This adds the newly created file to index. Another thing I noticed is occasionally I have to unplug and re-plug the tablet from the PC usb drive for the files appear. I believe this is an easier thing to ask of end-users than to have them reboot the tablet for the files to show up. Hope this helps someone out there!

此外,也可以直接用MediaScannerConnection 来,而不是需要重新construct一个.

File dir = new File(root + "/SensorData3");//     File dir = new File("/sdcard/SensorData");dir.mkdir();File file = new File(dir, "myData.txt");MediaScannerConnection.scanFile(this, new String[] {file.toString()},  null, new
MediaScannerConnection.OnScanCompletedListener() {@Override
public void onScanCompleted(String path, Uri uri) {
Log.d(TAG, "ExternalStorage Scaned: " + path + ":" );
Log.d(TAG, "ExternatalStore: " + "-> uri: " + uri);
}
});

转载于:https://my.oschina.net/simon203/blog/151112

无法在PC上找到,android app 创建的文件 问题.相关推荐

  1. PC上运行Android APP

    PC上运行Android APP android  简介 最近想在PC端使用多看阅读来看书,发现没有PC端软件.一般方法就是装个虚拟机比如bluestack,或者安装android-x86等. 偶然发 ...

  2. bliss android x86,Bliss OS现在可让您基于Android-x86和AOSP在PC上运行Android 10

    Bliss OS是一个基于Android-x86项目的开源操作系统,有望让您在任何Linux,Windows或Chromebook PC或平板电脑设备上运行最新的Android 10移动操作系统. B ...

  3. 如何在PC上运行Android系统?

    如果你希望在x86机或者x64电脑上安装Android的开源解决方案,那么不妨了解下Android-x86项目发布的最新版本,目前已经基于Android Oreo 8.1.固然在PC上运行Androi ...

  4. 使用USB在PC上操作Android手机

    使用USB在PC上操作Android手机 目录 使用USB在PC上操作Android手机 我的应用场景 环境介绍 基本原理 安装方法 几个常用命令 后记 我的应用场景 想上班的时候,通过笔记本直接阅读 ...

  5. android x86 oreo,Android-x86 8.1 RC1发布:PC上运行Android Oreo

    IT之家6月19日消息 在PC上运行Android系统的方式很多,但最可靠的还是Android-x86项目,现在其最新版已经发布,基于Android 8.1 Oreo. Android-x86是在PC ...

  6. android phone win10下载,微软Your Phone新功能: 可在Win 10 PC 上运行 Android 应用程序...

    今年 8 月,微软发布了一项 Your Phone 重大功能,可以在 Windows 10 PC 上运行 Android 应用程序.该功能主要通过 Your Phone 应用将 Android 应用投 ...

  7. 物联网模块ESP8266-01S实现PC端和Android APP同时连接通信

    本设计实现了PC端和Android APP与物联网模块ESP8266-01S通信. 1,Android APP采用E4A编写,PC端使用TCP调试助手. 首先最关键的需要对ESP8266-01S物联网 ...

  8. 成功解决无法安装64位版本的office,因为在您的PC上找到了以下32位程序,已有32位版本

    成功解决无法安装64位版本的office,因为在您的PC上找到了以下32位程序,已有32位版本 目录 解决问题 解决思路 解决问题 无法安装64位版本的office,因为在您的PC上找到了以下32位程 ...

  9. Office 2007 sp3 3in1 无法安装64位版本的 office ,因为在您的 PC 上找到了一下 32 位程序

    无法安装64位版本的 office ,因为在您的 PC 上找到了一下 32 位程序 我的thinkpad 老家伙已经运行了5年了 , 一直用的是office 2007 , 受够了它今天下决心把它换了 ...

最新文章

  1. Vue Router路由及路由重定向
  2. Linux系统管理技术
  3. mysql语言的简介_谁能帮我介绍一下 MY SQL ?
  4. 支付宝的一些小问题,注意事项等等,等用得时候在来写写
  5. 一行Python代码制作动态二维码
  6. 【java设计模式】【行为模式Behavioral Pattern】迭代器模式Iterator Pattern
  7. vue 后台重定向不成功_VUE 重定向不起效果了。
  8. sis 最新_《炙热的我们》火箭少女首胜,sis姐妹花遭遇惨败出局?
  9. gstat | 空间插值(二)——克里金插值之普通克里金
  10. python爬虫代码示例 动态_python动态爬虫的实例分享
  11. 在导出php,PDF导出在php
  12. 应用软件设计不是CRUD:如何进行应用系统功能模块的耦合性设计
  13. WebGL varying变量和颜色插值
  14. 微信答题小程序开发遇到过的坑
  15. dijkstra标号法表格_狄克斯屈拉dijkstra标号算法.pptx
  16. frp代理工具流量分析
  17. 分布式Ruby解决之道
  18. 弹窗广告关不掉?工信部:用这个方法举报!
  19. 自由职业需要我们知道什么呢?
  20. java全栈系列之JavaSE-面向对象(抽象类)041

热门文章

  1. 数据结构笔记(二十五)-- 图的基本术语
  2. c语言编程变色,【图片】(原创)用纯C变了个变色输出字符的程序。。。【c语言吧】_百度贴吧...
  3. rn php,RN和React路由详解及对比
  4. pid算法matlab仿真程序和c程序,pid算法matlab仿真程序和c程序.doc
  5. springboot主线程_springboot中的多线程.md
  6. ssh整合mysql不能自动生成表_ssh整合思想 Spring与Hibernate的整合 项目在服务器启动则自动创建数据库表...
  7. php安装sphinx扩展,安装php的sphinx扩展模块
  8. OpenCV-Python实战(18)——深度学习简介与入门示例
  9. java 获取文件扩展名_如何在Java中获取文件扩展名
  10. partition拼字符串_Python字符串partition(),rpartition()