0
사진을 여러 장 찍고 완료하면 장치에 보관하지 않고 WebService로 모두 보내고 싶습니다.Android : WebService로 사진을 보내십시오.
이미 전송 후 삭제를 시도했지만 성공하지 못했습니다.
가장 좋은 방법은 무엇입니까?
이것은 내 이미지 캡처 활동입니다.
private ImageView imgPreview;
private Button btnCapturePicture;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image_capture);
context = getApplicationContext();
imgPreview = (ImageView) findViewById(R.id.imgPreview);
btnCapturePicture = (Button) findViewById(R.id.btnCapturePicture);
/**
* Capture image button click event
* */
btnCapturePicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// capture picture
captureImage();
}
});
}
GPSTracker gps;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// if the result is capturing Image
if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
//TODO
gps = new GPSTracker(ImageCaptureActivity.this);
if (resultCode == RESULT_OK) {
// successfully captured the image
// display it in image view
previewCapturedImage();
//get gps location coordinates
if(gps.canGetLocation())
{
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: "
+ longitude, Toast.LENGTH_LONG).show();
//from latitude and longitude to address
Geocoder gcd = new Geocoder(context, Locale.getDefault());
List<Address> addresses = null;
try {
addresses = gcd.getFromLocation(latitude, longitude, 1);
} catch (IOException e) {
e.printStackTrace();
}
if (addresses.size() > 0) {
String tara = addresses.get(0).getCountryName();
String judet = addresses.get(0).getLocality();
String oras = addresses.get(0).getSubLocality();
String adresa = addresses.get(0).getAddressLine(0);
System.out.println(tara + ", " + judet + ", " + oras + ", " + adresa + "\n");
}
} else {
// Can't get location.
// GPS or network is not enabled.
// Ask user to enable GPS/network in settings.
Toast.makeText(getApplicationContext(), "Turn on GPS", Toast.LENGTH_LONG).show();
Intent backIntent = new Intent(ImageCaptureActivity.this, Cont.class);
startActivity(backIntent);
}
//TODO
//GET DATE OF IMAGE
String pathToFile = fileUri.getPath();
File file = new File(pathToFile);
if(file.exists()) {
String date = new SimpleDateFormat("dd-MM-yyyy HH-mm-ss").format(
new Date(file.lastModified())
);
Toast.makeText(context, date, Toast.LENGTH_LONG)
.show();
}
} else if (resultCode == RESULT_CANCELED) {
// user cancelled Image capture
Toast.makeText(getApplicationContext(),
"Cancelled", Toast.LENGTH_SHORT)
.show();
} else {
// failed to capture image
Toast.makeText(getApplicationContext(),
"Error!", Toast.LENGTH_SHORT)
.show();
}
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// save file url in bundle as it will be null on scren orientation
// changes
outState.putParcelable("file_uri", fileUri);
}
/*
* Here we restore the fileUri again
*/
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
// get the file url
fileUri = savedInstanceState.getParcelable("file_uri");
}
그리고 도우미 방법 :
private void captureImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}
/**
* Creating file uri to store image/video
*/
public Uri getOutputMediaFileUri(int type) {
return Uri.fromFile(getOutputMediaFile(type));
}
/*
* returning image/video
*/
private static File getOutputMediaFile(int type) {
// External sdcard location
File mediaStorageDir = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
IMAGE_DIRECTORY_NAME);
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d(IMAGE_DIRECTORY_NAME, "file"
+ IMAGE_DIRECTORY_NAME + " was not created");
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
File mediaFileName;
if (type == MEDIA_TYPE_IMAGE) {
mediaFileName = new File(mediaStorageDir.getPath() + File.separator
+ "IMG_" + timeStamp + ".jpg");
} else {
return null;
}
return mediaFileName;
}
/*
* Display image from a path to ImageView
*/
private void previewCapturedImage() {
try {
imgPreview.setVisibility(View.VISIBLE);
// bimatp factory
BitmapFactory.Options options = new BitmapFactory.Options();
// downsizing image as it throws OutOfMemory Exception for larger
// images
options.inSampleSize = 8;
final Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(),
options);
imgPreview.setImageBitmap(bitmap);
} catch (NullPointerException e) {
e.printStackTrace();
}
}
나는 REST WebService에에 사진을 보내려고합니다.
사람들이 도움을 줄 수 있도록 코드를 게시하면 매우 유용합니다. 귀하의 질문은 너무 일반적입니다. –
@ 키릴 _edited_ – Juvie22