gpt4 book ai didi

android - 无法在/mnt/sdcard 中创建文件夹

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:06:56 24 4
gpt4 key购买 nike

我想我做的一切都是正确的,首先创建一个文件夹我可以稍后在我的应用程序中写入,但它似乎不起作用。关于我如何失败的任何线索?

它正确地尝试创建/mnt/sdcard/gradebook

我有使用权限 android:name="android.permission.WRITE_EXTERNAL_STORAGE"在我的 list 中。我在真实设备 (Samsung Galaxy S) 上运行,但我没有使用SD 卡连接到我的计算机时用作存储。

    boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();

if (Environment.MEDIA_MOUNTED.equals(state)) {
// We can read and write the media
mExternalStorageAvailable = mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
// We can only read the media
mExternalStorageAvailable = true;
mExternalStorageWriteable = false;
Toast.makeText(this,"This Application needs a writable external storage (sdcard).",Toast.LENGTH_SHORT).show();
finish();
} else {
// Something else is wrong. It may be one of many other states, but all we need
// to know is we can neither read nor write
mExternalStorageAvailable = mExternalStorageWriteable = false;
Toast.makeText(this,"This Application needs a mounted external storage (sdcard).",Toast.LENGTH_SHORT).show();
finish();

}


File folder = new File(Environment.getExternalStorageDirectory () + "/gradeBook");
boolean success = false;
if(!folder.exists()){
success = folder.mkdir();
}
if (!success) {
Log.e("FILE", "can't create " + folder);
}
else
{
Log.i("FILE", "directory is created");
}

这是 list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ulsanonline.gradebook"
android:versionName="@string/version"
android:installLocation="auto"
android:versionCode="2">
<uses-sdk android:minSdkVersion="8"></uses-sdk>
<application
android:icon="@drawable/icon"
android:debuggable="true"
android:persistent="false"
android:hasCode="true"
android:minSdkVersion="8">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<activity
android:name=".CourseWork"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

最佳答案

uses-permission必须直接放置为 <manifest> child ,所以它应该是:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ulsanonline.gradebook"
android:versionName="@string/version"
android:installLocation="auto"
android:versionCode="2">
<uses-sdk android:minSdkVersion="8"></uses-sdk>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<application
android:icon="@drawable/icon"
android:debuggable="true"
android:persistent="false"

关于android - 无法在/mnt/sdcard 中创建文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6921018/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com