创建一个文件夹,并写入它的Andr​​oid的根 [英] Create a folder and write into it in the root of android

查看:149
本文介绍了创建一个文件夹,并写入它的Andr​​oid的根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是要写入在/ mnt / SD卡的外置SD。我试图创建一个文件夹,可以应用的文件,并让他们入店他人。

我有一个名为天秤座的一个应用程序,导出数据时生成的.csv文件和所有自动对焦它去/天秤座/文件夹。我想我的应用程序做同样的。

据我所看到的有外部存储这是SD和内部这对于应用程序中的非公共场所。

我怎样才能使一个目录在Android文件系统的根目录作为天秤座的呢?

如果我要求的外部存储,我得到了以下的非期望的位置:

  Environment.getExternalStorageDirectory()
 

  /存储/模拟/ 0 /(在我的Nexus)
到/ mnt / SD卡(在模拟器)
 

如果我尝试使该文件夹的绝对路径/ MyDiary它会返回错误创建文件夹

 文件夹=新的文件(/ MyDiary);
布尔成功= TRUE;
如果(!folder.exists()){
        成功= folder.mkdir();
}
如果(成功){
        Toast.makeText(getBaseContext(),已经存在,Toast.LENGTH_LONG).show();
} 其他 {
        Toast.makeText(getBaseContext(),错误创建目录,Toast.LENGTH_LONG).show();
        返回;
}
 

如果我尝试检查,如果天秤座的文件夹不存在,它说,它不存在:

 文件夹=新的文件(/天秤座);
布尔成功= TRUE;
如果(!folder.exists()){
        成功= folder.mkdir();
}
如果(成功){
        Toast.makeText(getBaseContext(),天秤存在,Toast.LENGTH_LONG).show();
}
 

注:我已经得到了明显的权限在外部存储写

解决方案

根是一个ramdisk。而在它的一些文件夹是由init.rc.创建只有init.rc有权限在ramdisk上创建文件夹。 如果您通过init.rc的文件夹,你仍然需要init.rc帮助安装一个真正的stroage设备​​上的新文件夹。

重新包装如再生的重启 <的init.rc文件/ P>

I'm not trying to write into the external sd at /mnt/sdcard. I'm trying to create a folder for may app files and have them accesible by others.

I have an app called Libra that generates .csv files when exporting data and all af it goes to /Libra/ folder. I want my app to do the same.

As far as I've seen there's external storage which is the sd and internal which is a non public place for the app.

How can I make a dir at the root of the android file system as Libra does ?

If I ask for the external storage I get the following non desired locations :

Environment.getExternalStorageDirectory()

/storage/emulated/0/ (in my Nexus)
/mnt/sdcard          (in the emulator)

If I try to make the folder in an absolute path /MyDiary It returns Error creating folder

File folder = new File("/MyDiary");
boolean success = true;
if (!folder.exists()) {
        success = folder.mkdir();
}
if (success) {
        Toast.makeText(getBaseContext(), "Already exists", Toast.LENGTH_LONG).show();
} else {
        Toast.makeText(getBaseContext(), "Error creating directory", Toast.LENGTH_LONG).show();
        return;
}

If I try to check if the Libra folder does exists, it says it doesn't exist:

File folder = new File("/Libra");
boolean success = true;
if (!folder.exists()) {
        success = folder.mkdir();
}
if (success) {
        Toast.makeText(getBaseContext(), "Libra exists", Toast.LENGTH_LONG).show();
}

Note: I've got the manifest permissions to write in external storage.

解决方案

The root is a ramdisk. And the folder in it some are created by init.rc. Only init.rc have permission to create the folder in the ramdisk. If you create the folder by init.rc, you still need init.rc help to mount a true stroage device on the new folder.

Repack like The init.rc file regenerated on restart

这篇关于创建一个文件夹,并写入它的Andr​​oid的根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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