0

清单有

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

应用程序设置,“存储”= 修改/删除 SD 卡内容“在运行 2.3.5 的三星平板电脑和运行 2.3.4 的摩托罗拉 Droid 上的结果相同。设备不受开发机器的束缚。

代码如下:

public class OutputStudentRecords extends StActivity{
   SharedPreferences mStudentSettings;
    protected Cursor mCursor;
    boolean mExternalStorageAvailable = false;
    boolean mExternalStorageWriteable = false;

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.create_csv);

        String state = Environment.getExternalStorageState();
        Toast.makeText(getApplicationContext(),"State is " + state, Toast.LENGTH_LONG).show();

        if (!Environment.MEDIA_MOUNTED.equals(state)){
            //We can read and write the media
            mExternalStorageAvailable = mExternalStorageWriteable = true;
            Toast.makeText(getApplicationContext(), "We Can Read And Write ", Toast.LENGTH_LONG).show();
              File file = new File(Environment.getExternalStorageDirectory()
                     +File.separator
                     +"studentrecords"); //folder name
                     file.mkdir();
        } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)){
              mExternalStorageAvailable = true;
              mExternalStorageWriteable = false;
              Toast.makeText(getApplicationContext(), "We Can Read but Not Write ", Toast.LENGTH_LONG).show();
          }else{
                //something else is wrong
                mExternalStorageAvailable = mExternalStorageWriteable = false;
                Toast.makeText(getApplicationContext(), "We Can't Read OR Write ", Toast.LENGTH_LONG).show();
          }

        }

}  

Toast 返回 State="mounted" 但它会在两台机器上跳到“我们无法读取或写入”。我错过了一些东西但找不到它,任何帮助将不胜感激。

谢谢

4

1 回答 1

6

也许你应该改变这个:

if (!Environment.MEDIA_MOUNTED.equals(state)){

进入这个:

if (Environment.MEDIA_MOUNTED.equals(state)){

(即:删除“!”)

于 2013-05-09T22:03:10.327 回答