无法写入SD卡上的文件的android [英] Unable to write files on sdcard android

查看:175
本文介绍了无法写入SD卡上的文件的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,从而节省了SD卡备份文件。它工作正常,在HTC的Nexus One和其他Android手机,但也有一些手机不工作(读或写)。

I have an app which saves backup files on SD-Card. It works fine on HTC Nexus One, and other android phones, but with some phones it doesn't work (reading or writing).

在清单中我已经设置的:

In the manifest I have set this:

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />  

例如(当我设置记录文件的路径):

For example (when I set the path for recording file) :

OutputStream output = new FileOutputStream(Environment.getExternalStorageDirectory()
                    + "/mydata.dat");
//Writing file...(It doesn't work)

我怎样才能得到Micro-SD卡的正确路径正确操作文件?

How I can get the right path of the SD-Card for manipulating files rightly?

推荐答案

当你说这是行不通的......到底发生了什么?你的意思是程序运行无投诉,但该文件不被写入到SD卡,或者你的意思是什么东西?

When you say "it doesn't work".... what exactly happens? Do you mean the program runs without complaint but the file doesn't get written to the sdcard, or do you mean something else?

如果该文件根本就没有到达那里,这不是你的错,这是手机制造商的过错。我已经看到了,从getExternalStorageDirectory()返回到/ mnt / SD卡几个设备,然而,这并不是真正意义上的路径SD卡!在至少一个摩托罗拉的设备和三星Galaxy Tab(7),例如,到/ mnt / SD卡返回即使这指向内部存储,并在这些设备的外部存储到/ mnt / SD卡-EXT

If the file is simply not getting there, it's not your fault, it's the phone manufacturer's fault. I've seen several devices that return "/mnt/sdcard" from getExternalStorageDirectory(), however this is not truly the path to the sdcard! On at least one Motorola device and on the Samsung Galaxy Tab (7"), for example, /mnt/sdcard is returned even though this points to internal storage, and the external storage on each of these devices is /mnt/sdcard-ext.

没有什么合法的,你可以做到这一点 - 在OEM是骗你的。如果你想的黑客工作,你都可以读的/ proc /坐骑,试图找到实际的路径SD卡,但到/ mnt / SD卡也将显示在那里,而且也没有万无一失的方法来区分的真理所有设备。

There's nothing legitimately you can do about this -- the OEM is lying to you. If you want a hack of a work-around, you can read /proc/mounts and try to find the actual path to the sdcard, but /mnt/sdcard will also show up there, and there's no guaranteed way to distinguish the truth for all devices.

这篇关于无法写入SD卡上的文件的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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