Android:外部存储权限问题:

发布于 2024-12-01 23:50:54 字数 1290 浏览 0 评论 0原文

我真的需要有人指导我解决外部存储或 SD 卡的一些问题。我不会讨论复杂性。我有一个名为 MyVideos 的文件夹。它位于 Motrola Xoom 的 SD 卡文件夹中;路径是 "/mnt/sdcard-ext/MyVideos. 该文件夹已经存在。但是,我遇到了一些奇怪的错误..例如,如果我检查该文件夹是否存在使用以下代码:

File myDirectory = new File(defaultStorage, "/MyVideos/"); 
if (myDirectory.exists())
{  
my code: lets say true
}
else
{
my code: false
}

其中 defaultStorage is = "/mnt/sdcard-ext" 它总是返回 false。它应该返回 true,因为该文件夹确实存在于该文件夹中。 执行其他操作

for (File f : myDirectory.listFiles()) 
    {
        if (f.isFile())
        {
            filenames.add(f.getName()); //add to array

        }//if closes
     }//for closes

像我一样 以下行的致命异常

for (File f : myDirectory.listFiles())

错误堆栈如下:

E/AndroidRuntime(22644): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity         
E/AndroidRuntime(22644): Caused by: java.lang.NullPointerException

我刚刚提到了堆栈中重要的内容。准确地说,它是一个 NullPointerException,尽管我

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

在清单文件中使用它,但它不起作用。最令人惊讶的元素是它在这里运行良好;但有一个在美国的客户,它在他的所有设备上崩溃了。英国或其他国家的设备的权限设置有什么不同吗?美国..我将感谢如果你在这里帮助我的话..这对我来说是一个大问题。 谢谢

I really need someone here to guide me about some issues with the external storage OR sd-card. I won't go into complexities. I have a folder with the name of MyVideos. It is located in the sd-card folder of Motrola Xoom; the path is "/mnt/sdcard-ext/MyVideos. The folder is already there. However, there are some strange errors I am having.. For example, if I check if the folder exists or not using the following code:

File myDirectory = new File(defaultStorage, "/MyVideos/"); 
if (myDirectory.exists())
{  
my code: lets say true
}
else
{
my code: false
}

where defaultStorage is = "/mnt/sdcard-ext". It always return false. It should return true since the folder surely exists there. And assuming that the folder exists there, I perform other operations like

for (File f : myDirectory.listFiles()) 
    {
        if (f.isFile())
        {
            filenames.add(f.getName()); //add to array

        }//if closes
     }//for closes

I get FATAL exception at the following line

for (File f : myDirectory.listFiles())

The error stack is below:

E/AndroidRuntime(22644): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity         
E/AndroidRuntime(22644): Caused by: java.lang.NullPointerException

I have just mentioned the things that are important from the stack. It is a NullPointerException to be precise. Although I am using

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

in my manifest file. Even then it doesn't work. The most surprising element is that it is running fine here; but there is a client in USA, it is crashing on all his devices.. Is there any difference in the permission settings of devices in UK or in USA.. I shall be thankful to you if you help me here.. It is a big problem for me.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡 2024-12-08 23:50:54

根据 文档,您描述的状态意味着您无法访问外部媒体存储:

public static final String MEDIA_SHARED

添加到 API 级别 1 getExternalStorageState() 如果媒体存在且未安装且通过 USB 共享,则返回 MEDIA_SHARED海量存储。

常数值:“共享”

您需要转到 USB 大容量存储选项并关闭 USB 存储。

PS:感谢 DigCamara,我从这个 SO 答案复制。

谢谢

According to the documentation, the state you're describing means that the external media storage isn't accessible to you:

public static final String MEDIA_SHARED

Added in API level 1 getExternalStorageState() returns MEDIA_SHARED if the media is present not mounted, and shared via USB mass storage.

Constant Value: "shared"

You need to go to your USB Mass Storage options and turn off USB storage.

PS : Thanks to DigCamara I copied from this SO answer.

Thanks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文