2012-05-29 43 views
1

我有一個應用程序在android中捕捉圖像,然後將它們保存到Emualtor畫廊Fine.But我必須將所有照片庫中的服務器,當我從手機捕獲他們應該自動地上傳到服務器並從圖庫中刪除即要將圖像移動到服務器。請告訴我如何從圖庫中選擇所有圖像,然後將它們移動到服務器。移動圖片從圖庫到服務器在android

回答

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(); 
} 
} 

方法烏里轉化爲實際的路徑

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; 
} 
+0

先生什麼會做這個代碼?如果我在我的問題中需要,這會對我有用嗎? – user1397781