Creating a folder programmatically on a Xoom

喜你入骨 提交于 2019-12-11 23:15:30

问题


The Xoom does not have a working SD slot, so Moto decided to re-route calls to External Storage to the internal storage:

String path = Environment.getExternalStorageDirectory().getPath() + "/newfolder/";

The above line returns a path to the Internal storage on the Xoom, and to the SD card on my Droid.

However, I am having trouble writing to this path on a Xoom. It's as if it is write protected, or I do not have permission.

This code creates a folder on my Droid's SD card, but not on my Xoom's storage:

File file = new File(path);
file.mkdir();

One thought was that since the Xoom is only "faking" that it is external storage, maybe the app needs the "internal storage" permission as well, but that did not fix it.


回答1:


on my xoom it´s working like this:

    private File path;
    path = new File(Environment.getExternalStorageDirectory().toString() + "/audio");
    path.mkdirs();

mkdirs (with ending s), because then missing dirs on the way to the end-path are automatically created.

are you sure you´re having this in your AndroidManifest?

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



回答2:


I was having same problem in my Nexus S running android 2.3.4, after playing around with stk's code I was able to create a folder.

Here is the final code:

File root = new File(Environment.getExternalStorageDirectory().toString()+"//MyFolder");
root.mkdirs();

Simply replaced "/audio" with "//audio" in stk's code and it worked for me.

You should have write permission in your AndroidManifest under tag.

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


来源:https://stackoverflow.com/questions/6218572/creating-a-folder-programmatically-on-a-xoom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!