我在Android中有一个应用程序用于捕获图像,然后将它们保存到Emualtor画廊Fine.But我必须将所有照片在库中移动到服务器当我从手机捕获它们时它们应该自动上传到服务器并从库中删除ie想要将图像移动到服务器。请告诉我如何从图库中选择所有图像,然后将它们移动到服务器。
答案 0 :(得分:0)
调用相机
String fileName = String.valueOf(System.currentTimeMillis()) + ".jpg";
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
mCapturedImageURI = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
startActivityForResult(cameraIntent, 1234);
处理图像
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK && requestCode == 1234) {
String filepath = getPathfromUri(mCapturedImageURI);
//Now you have the file path. upload it to server.
//uploadtoserver(filepath);
//Now delete it after uploading
new File(filepath).delete();
}
}
将Uri转换为实际路径的方法
public String getPathfromUri(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
startManagingCursor(cursor);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String path= cursor.getString(column_index);
cursor.close();
return path;
}