清单
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
应用程序设置,'存储'=修改/删除SD卡内容' 三星平板电脑运行2.3.5和摩托罗拉Droid运行2.3.4的结果相同。 设备没有连接到开发机器。
代码如下:
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 =“已挂载”,但它会在两台计算机上跳到“我们无法读取或写入”。我错过了一些但却找不到的东西,任何帮助都会受到赞赏。
谢谢
答案 0 :(得分:4)
也许你应该改变这个:
if (!Environment.MEDIA_MOUNTED.equals(state)){
进入这个:
if (Environment.MEDIA_MOUNTED.equals(state)){
(即:删除&#34;!&#34;)