我只是尝试通过代码将文件上传到服务器,如果我从模拟器访问文件,它工作正常,
路径data/app/07312012_135528.3gp并获取服务器响应200,OK
但是当我通过设备访问要上传的文件时出现错误400,错误请求 当文件存在于 SDCard 中并且通过 File.exists() 检查时。
我的手机是三星 Galaxy Ace
HttpPost postRequest = new HttpPost(ServerURL);
MultipartEntity reqEntity = new MultipartEntity();
File dir = Environment.getExternalStorageDirectory();
File yourFile = new File(dir, "tdsongdata/07312012_135528.3gp");
// path becomes "/mnt/sdcard/tdsongdata/07312012_135528.3gp"
if(yourFile.exists())
{
reqEntity.addPart("email", new StringBody("esetylo@gmail.com"));
reqEntity.addPart("password", new StringBody("123"));
reqEntity.addPart("title", new StringBody("The new file"));
reqEntity.addPart("musicData", new FileBody(yourFile));
}
但是当我尝试从设备中的同一路径播放它时,它会成功播放音频
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource("/mnt/sdcard/tdsongdata/07312012_135528.3gp");
mp.prepare();
mp.start();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
不明白问题出在哪里,请帮忙
最佳答案
将您的手机语言更改为英语(美国)。重新启动您的设备并重试。
关于java - Android:文件在模拟器中工作但在设备中出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11812549/