困惑:那些誰投下來的一個問題,你可以添加一些意見,爲什麼????我想說不好的話,只是不想被禁止。文件夾中創建一個文件
我有一個應用程序,我想有一個文件夾在SD卡,使用戶可以添加一些東西,然後我可以用它在應用程序中。我用下面的代碼來創建一個文件夾:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//External storage
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;
Log.v("Storage","ablo to read and write");
//create Beatss folder
File direct = new File(android.os.Environment.getExternalStorageDirectory().getPath() + "/Beatss");
Log.v("Storage",android.os.Environment.getExternalStorageDirectory().getPath() + "/Beatss");
boolean success = true;
if (!direct.exists()) {
success = direct.mkdirs();
}
if (success) {
// Do something on success
Log.v("Storage","Folder has been created");
} else {
// Do something else on failure
}
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
// We can only read the media
mExternalStorageAvailable = true;
mExternalStorageWriteable = false;
Log.v("Storage","ablo to read only");
} else {
mExternalStorageAvailable = mExternalStorageWriteable = false;
Log.v("Storage","no access");
}
我可以在DDMS看到該文件夾已創建,但是當我經歷WindowsExplorer我有一個文件的文件夾,而不是。那麼,如何創建一個文件夾?
UPD1:所以,即使我在這個文件夾內創建了一些東西,我仍然把它作爲一個文件在Windows資源管理器裏面,但是在DDMS裏面,我可以看到我有一個文件夾,裏面有另一個文件夾。那麼,這裏有什麼問題呢?
UPD2:那麼,breaked起來的logcat direct
線,看是否有真正的路徑:
01-24 21:14:04.368: V/Storage(12116): /mnt/sdcard/Beatss/
所以有..
UPD3:我不能展示我所有的代碼是264到目前爲止。所有這個文件夾創建發生在mainActivity的onCreate。在manifest資源配置文件看起來是這樣的:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.test
android:versionCode="1"
android:versionName="1.0"
android:installLocation="auto" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="16" />
<supports-screens
android:smallScreens= "true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="false"
/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:screenOrientation="portrait"
>
<activity
android:name=".Main"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:clearTaskOnLaunch="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity android:name=".SupportScreen"
android:label="@string/app_name"
android:screenOrientation="portrait">
</activity>
<activity android:name="com.tapjoy.TJCOffersWebView" android:configChanges="keyboardHidden|orientation" />
<activity android:name="com.tapjoy.TapjoyFullScreenAdWebView" android:configChanges="keyboardHidden|orientation" />
<activity android:name="com.tapjoy.TapjoyDailyRewardAdWebView" android:configChanges="keyboardHidden|orientation" />
<activity android:name="com.tapjoy.TapjoyVideoView" android:configChanges="keyboardHidden|orientation" />
</application>
</manifest>
更新代碼上:
logcat的說:
01-24 21:19:21.068: V/Storage(14088): /mnt/sdcard/Beatss/
01-24 21:19:21.138: V/Storage(14088): Folder has been created
如果您在此「文件夾」內創建文件或之後檢查了「direct.isDirectory()」,會發生什麼情況? ;) – ConcurrentHashMap
從來沒有嘗試過...有趣的 – Daler
只是一個警告 - 不要關閉用戶找到他們的sdcard與十幾個目錄遍佈SD卡 - 使其習慣存儲在'/ SD卡/ Android /我的.pkg.name/.....'使最終用戶更容易清理,如果需要的話; ...) – t0mm13b