2011-12-05 3 views
3

외부 저장소에 폴더를 만들려고하는데 여기서 다른 두 개의 스레드를 따라갔습니다. 그러나, 비록 그들이 나타내는 것을하고있는 것처럼 보이지만, 창조는 실패합니다. 여기 은 안드로이드 장치의 외부 저장소에 폴더를 만들 수 없습니다.

코드의 조각이다

boolean mExternalStorageAvailable = false; 
    boolean mExternalStorageWriteable = false; 

    String state = Environment.getExternalStorageState(); 
    if (Environment.MEDIA_MOUNTED.equals(state)) { 
     mExternalStorageAvailable = true; 
     mExternalStorageWriteable = true; 
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { 
     mExternalStorageAvailable = true; 
     mExternalStorageWriteable = false; 
    } else { 
     mExternalStorageAvailable = false; 
     mExternalStorageWriteable = false; 
    } 
    File exst = Environment.getExternalStorageDirectory(); 
    String exstPath = exst.getPath(); 

    File fooo = new File(exstPath+"/fooo"); 
    boolean success = fooo.mkdir(); 

내가 그것을 실행하면, 내가 얻을이 : 여기

mExternalStorageAvailable = true; 
mExternalStorageWriteable = true; 
success = false; 

전체 매니페스트 파일입니다 :

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.mydev.mobile.Test" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk android:minSdkVersion="8" /> 

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <activity 
     android:label="@string/app_name" 
     android:name=".TestIndexSearchForHitsAndroidActivity" > 
     <intent-filter > 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

무엇 내가 틀렸어? 감사!

답변

4
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.mydev.mobile.Test" 
android:versionCode="1" 
android:versionName="1.0" > 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
... 
.... 
</maifest> 
+0

Namari 줘, 덕분에 많은 일했다! 하지만 전에 왜 작동하지 않았는 지 설명해 주시겠습니까? 내가 사용한 몇 가지 예제에서, 그들은''아래에'WRITE_EXTERNAL_STORAGE' 행을 가지고 있었고 나는 그것들이 효과가 있다고 주장했다고 ​​생각합니다. –

+0

http://developer.android.com/guide/topics/security/security.html – confucius

1

측면 밖으로

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

< 응용 프로그램> 태그

관련 문제