不能够写入SD卡,同时屏幕关闭,即使我有PARTIAL_WAKE_LOCK [英] Not able to write to SDCard while screen is off even though I have PARTIAL_WAKE_LOCK

查看:801
本文介绍了不能够写入SD卡,同时屏幕关闭,即使我有PARTIAL_WAKE_LOCK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全对Java和Android,所以我想我可能失去了一些东西明显。
我正在写一个应用程序,我品尝了方向感应器,并把结果写入对SD卡的文件,以及在屏幕上的日志显示。
而屏幕上的一切工作正常。因为我想同时屏幕会变暗以同时经营,我加code收购PARTIAL_WAKE_LOCK。
从我可以告诉,当屏幕变暗的传感器仍然被采样(让我想起了唤醒锁的工作),但没有任何结果被写入SD卡。我觉得这是发生了什么,因为当我通过pressing菜单键再次唤醒屏幕,屏幕上的日志有显示的所有过渡所发生而屏幕是关闭的。但是,当我看到在SD卡上创建的文件,记录在文件中唯一的转换是同时屏幕是在发生的人。
至于我怎么写我都试过了文件(我认为我在说这个吧...)一个FileWriter包裹在BufferedWriter和包裹在一个FileOutputStream一个FileWriter。
起初,方向感应器没有,即使我有唤醒锁,直到我学会周围,我加一个BroadcastReceiver为Intent.ACTION_SCREEN_OFF,当我得到它,我注销方向监听工作的工作,然后重新注册。
我是否需要注销的FileWriter的和重新注册,它的东西?
怪异的是,输出文件包含Intent.ACTION_SCREEN_OFF之前的所有方向的变化被接收,和他们都Intent.ACTION_SCREEN_ON之后,当我开机画面备份收到,但没有在两者之间。

I'm totally new to Java and Android, so I think I'm probably missing something obvious. I'm writing an app where I sample the orientation sensor and write the result to a file on the SDCard as well as display it in a log on the screen. Everything works fine while the screen is on. Since I want to also operate while the screen goes dark, I added code to acquire a PARTIAL_WAKE_LOCK. From what I can tell, when the screen goes dark the sensors are still being sampled (making me think the wake lock worked), but none of the results are written to the SDCard. I think this is what is happening, because when I reawaken the screen by pressing the menu key, the log on the screen has all the transitions displayed that took place while the screen was off. But, when I look at the file created on the SD card, the only transitions recorded in the file are the ones that occurred while the screen was on. As for how I'm writing the file I have tried (I think I'm saying this right...) a FileWriter wrapped in BufferedWriter, and a FileWriter wrapped in a FileOutputStream. At first, the orientation sensor wasn't working even though I had the wake lock until I learned a work around where I added a BroadcastReceiver for Intent.ACTION_SCREEN_OFF and when I get it, I unregister the orientation listener, then re-register it. Do I need to "unregister" the FileWriter and "re-register" it or something? The weird part is that the output file contains all orientation changes before the Intent.ACTION_SCREEN_OFF is received, and all of them after Intent.ACTION_SCREEN_ON is received when I power the screen back up, but nothing in between.

我在写为Android 1.6(我有一个G1)
我的项目设置为使用SDK 4

I'm writing for Android 1.6 (I have a G1) My project is set to use SDK 4

推荐答案

您检查,如果外部存储可作为的此处描述?它可以是在那时根本不可写。还有<一个href=\"http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory%28%29\"相对=nofollow> $ C $在文档Ç的一个外部存储广播接收器。你可以用它来等待,直到存储可用之前写

Are you checking if external storage is available as described here? It may be simply unwritable at that time. There's also code in the docs for a external storage BroadcastReceiver. You could use that to wait until storage is available before writing.

这篇关于不能够写入SD卡,同时屏幕关闭,即使我有PARTIAL_WAKE_LOCK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆