如何在android的SD卡创建的文件夹 [英] How to create folder in sdcard in android

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

问题描述

我想在我的SD卡的文件夹和我用下面的code:

I want to make folders in my sdcard and I have used the code below:

public class Screen extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome);

        operateOnFirstUsage();
    }

    private void operateOnFirstUsage() {

        String state = Environment.getExternalStorageState();
        Log.d("Media State", state);

        if (Environment.MEDIA_MOUNTED.equals(state)) {
            File appDirectory = new File(
                    Environment.getExternalStorageDirectory().getAbsolutePath() + "/MyApp/");

            Log.d("appDirectroyExist", appDirectory.exists() + "");
            if (!appDirectory.exists()) 
                Log.d("appDir created: ", appDirectory.mkdir() + "");

            File dbDirectory = new File(
                    Environment.getExternalStorageDirectory().getAbsolutePath() + "/MyApp/Database/");

            Log.d("dbDirectroyExist", dbDirectory.exists() + "");
            if (!dbDirectory.exists())
                Log.d("dbDir created: ", dbDirectory.mkdirs() + "");


            File themesDirectory = new File(
                    Environment.getExternalStorageDirectory().getAbsolutePath() + "/MyApp/Themes/");
            Log.d("themesDirectroyExist", themesDirectory.exists() + "");
            if (!themesDirectory.exists()) 
                Log.d("themesDir created: ", themesDirectory.mkdirs() + "");

        }
    }
}

另外,我已经设置了SD卡写入权限:

Also, I have set the sdcard write permission:

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

我已经运行应用程序几次,每次我得到的LogCat中输出:

I've run the application several times and every time I get the LogCat output:

01-09 21:38:13.701: D/Media State(15363): mounted
01-09 21:38:13.701: D/appDirectroyExist(15363): false
01-09 21:38:13.701: D/appDir created:(15363): false
01-09 21:38:13.701: D/dbDirectroyExist(15363): false
01-09 21:38:13.701: D/dbDir created:(15363): false
01-09 21:38:13.701: D/themesDirectroyExist(15363): false
01-09 21:38:13.701: D/themesDir created:(15363): false

我看过类似的问题,但没有得到有用的。我应该怎么做,以获得$ ​​C $ C运行?我的问题是什么?

I have read similar question, but nothing useful to get. What should I do to get the code running? What is my problem?

推荐答案

我不知道为什么应用程序行事的方式,但最后我通过删除并重新在Android清单文件的SD卡写入权限克服了这个问题。感谢大家对你的帮助和你的时间表示歉意。

I don't know why the application acted that way, but finally I overcame this problem by removing and resetting the sdcard write permission in the Android manifest file. Thanks all of you for your kind help and apologize for taking your time.

这篇关于如何在android的SD卡创建的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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