我用了我的回答我的问题我自己:-D所以这里是谁了同样的问题解决....首先,我才知道,在服务器端插座URI不工作“的文件这个文件路径:/ //mnt/sdcard/APK/Video.apk“或其他类型的文件uri。只有“/mnt/sdcard/APK/Video.apk”在socket上工作。因此,从文件URI字符串其中有来自内容提供商得到的,我创造了我的服务器套接字文件。然后创建一个文件之后...我已经得到了我也文件大小....
private void addSDFileEntity(final Uri uri, HttpResponse response)
throws IOException {
if (mTransferStartedListener != null) {
mTransferStartedListener.started(uri);
}
Cursor c = mContext.getContentResolver().query(uri, null, null, null,
null);
c.moveToFirst();
int nameIndex = c.getColumnIndexOrThrow(NewSDCardContentProvider.SDFiles.Columns.DISPLAY_NAME);
String name = c.getString(nameIndex);
int dataIndex = c.getColumnIndexOrThrow(NewSDCardContentProvider.SDFiles.Columns._DATA);
String dataname = c.getString(dataIndex);
Uri data = Uri.parse(dataname);
if (name.endsWith(".pdf")) {
String contentTypepdf = "application/pdf";
File myFile = new File(dataname);
int reqLen = (int) myFile.length();
Log.d("apk len===>", "" + reqLen);
InputStream fis = new FileInputStream(myFile);
response.addHeader("Content-Type", contentTypepdf);
response.addHeader("Content-Length", "" + reqLen);
response.setEntity(new InputStreamEntity(fis, reqLen));
if (socket == null) {
socket.close();
}
}
if (name.endsWith(".apk")) {
String contentTypeapk = "application/vnd.android.package-archive";
File myFile = new File(dataname);
int reqLen = (int) myFile.length();
Log.d("apk len===>", "" + reqLen);
InputStream fis = new FileInputStream(myFile);
response.addHeader("Content-Type", contentTypeapk);
response.addHeader("Content-Length", "" + reqLen);
response.setEntity(new InputStreamEntity(fis, reqLen));
}
现在我在服务器套接字发送我的文件内容....
private void sendSDFileContent(
DefaultHttpServerConnection serverConnection,
RequestLine requestLine) throws IOException, HttpException {
HttpResponse response = new BasicHttpResponse(new HttpVersion(1, 1),
200, "OK");
String SDfileId = getSDFileId(requestLine.getUri());
Log.d("selected URI from server", SDfileId);
addSDFileEntity(Uri.withAppendedPath(
NewSDCardContentProvider.SDFiles.CONTENT_URI, SDfileId),
response);
serverConnection.sendResponseHeader(response);
serverConnection.sendResponseEntity(response);
}