2
A
回答
0
該代碼上傳數據(圖片,MP3的,文本文件等)HTTP
服務器:
2
您可以使用此代碼拍攝圖庫圖像對話框。
mUploadButton = (Button) findViewById(R.id.uploadButton);
mUploadButton.setOnClickListener(new OnClickListener() {//this button is used for pickup gallery image.
public void onClick(View v) {
Intent rselect = new Intent(Intent.ACTION_GET_CONTENT, null);
rselect.setType("image/*");
rselect.putExtra("return-data", true);
startActivityForResult(rselect, 1);
}
});
onActivityResult()被用於
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 1:
if(requestCode == 1 && data != null && data.getData() != null){
// Bundle params = new Bundle();
// params.putString("method", "photos.upload");
// intent's getData() returns a Uri describing
// the data which the intent holds
Uri _uri = data.getData();
if (_uri != null) {
//User had pick an image.
Cursor cursor = getContentResolver().query(_uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
cursor.moveToFirst();
//Link to the image
final String imageFilePath = cursor.getString(0);
Log.v("imageFilePath", imageFilePath);
File photos= new File(imageFilePath);
long length = photos.length();
byte[] imgData = new byte[(int) length];
FileInputStream pdata = null;
try {
pdata = new FileInputStream(photos);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
pdata.read(imgData);//imgdata is an array where you get byte data for selected image from gallery and ready to upload.
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
cursor.close();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
}
0
相關問題
- 1. android將圖像上傳到服務器
- 2. 將圖像上傳到服務器並將url保存到服務器
- 3. 無法上傳圖像並將其保存在服務器上
- 4. 如何在Android SDK中將圖像上傳到服務器
- 5. 如何將圖像上傳到服務器在android phonegap
- 6. 如何保存畫布圖像上傳到服務器之前?
- 7. 使用ColdFusion將上傳的圖像保存到服務器
- 8. PHP - 將上傳的圖像保存到服務器
- 9. 如何在iOS上將圖像數據上傳到服務器?
- 10. 如何使用Retrofit2上傳圖像並將其保存在NodeJS服務器上?
- 11. 如何將圖像上載到服務器並保存路徑
- 12. 如何上傳圖像到服務器
- 13. 將圖像上傳到服務器symfony2
- 14. 將圖像上傳到服務器ImageSwitcher
- 15. 將圖像上傳到從服務器
- 16. 將圖像上傳到服務器angularjs
- 17. 將圖像上傳到服務器
- 18. 無法上傳保存在服務器上的圖像
- 19. [Android] - 將圖片上傳到服務器
- 20. 將base64映像上傳到php服務器並保存到MySql
- 21. PHP服務器:保存(上傳)從Android的圖像與改造
- 22. 如何將圖像上傳到服務器上的變化
- 23. 上傳圖像服務器上傳圖像服務器
- 24. 如何上傳視頻或圖像到服務器在android
- 25. 將圖像上傳到服務器上之前旋轉圖像
- 26. 將圖像上傳到服務器的形式在Android
- 27. 在android中將文件和圖像上傳到php服務器
- 28. 在java中上傳圖像並將其保存在服務器上。沒有Html5
- 29. 如何上傳圖像到服務器,而不使用上傳按鈕在android
- 30. R Shiny:上傳圖像文件並保存到服務器
,我怎麼可以將圖像保存到服務器 – AB1209