[英]Writing a file to nexus 4 device is not working
我正在嘗試使用以下代碼在設備上創建文件
private void createFileOnDevice(Boolean append) throws IOException {
File Root = Environment.getExternalStorageDirectory();
if (Root.canWrite()) {
File LogFile = new File(Root, "log.txt");
FileWriter LogWriter = new FileWriter(LogFile, append);
out = new BufferedWriter(LogWriter);
Date date = new Date();
out.write("Logged at"
+ String.valueOf(date.getDay() + "-" + date.getHours()
+ ":" + date.getMinutes() + ":" + date.getSeconds()
+ "\n"));
}
}
代碼運行良好,當我在具有Android 2.3.5至4.3版本的設備上運行時,它將創建一個文件。
但是,當我在具有最新Android版本(4.4.2,kitkat)的Nexus 4上運行相同的應用程序時,我無法創建該文件。 另外,我沒有任何錯誤。
我如何解決它??..
提前致謝 :):)
問題可能是在nexus 4上缺少外部存儲...
測試時,是否要在調試模式下進行測試? 如果是這樣,您的操作系統將可以訪問nexus 4上的存儲,而不能訪問電話。 當手機可以訪問存儲設備時嘗試進行測試,然后看看會發生什么...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.