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