Changed the way to create the temp file, to use the Image utility method to create a temp file.

parent aed65324
...@@ -6,17 +6,26 @@ import android.content.Intent; ...@@ -6,17 +6,26 @@ import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.Toast; import android.widget.Toast;
import com.aluxoft.earrecognition.utils.ImageUtils;
import org.apache.commons.io.FileUtils;
import org.opencv.highgui.Highgui;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ActivityEarCapture extends Activity { public class ActivityEarCapture extends Activity {
...@@ -76,13 +85,13 @@ public class ActivityEarCapture extends Activity { ...@@ -76,13 +85,13 @@ public class ActivityEarCapture extends Activity {
public void onClick(View v) { public void onClick(View v) {
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
try { try {
location = File.createTempFile("image" + System.currentTimeMillis(), ".jpg"); location = ImageUtils.createTempImageFile();
} catch (IOException e1) { } catch (IOException e1) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e1.printStackTrace(); e1.printStackTrace();
return; return;
} }
// if this gets modified, the onActivityResult in // if this gets modified, the onActivityResult in
// FormEntyActivity will also need to be updated. // FormEntyActivity will also need to be updated.
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(location)); i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(location));
...@@ -92,7 +101,7 @@ public class ActivityEarCapture extends Activity { ...@@ -92,7 +101,7 @@ public class ActivityEarCapture extends Activity {
Toast.makeText(ActivityEarCapture.this, "No Camera", Toast.LENGTH_SHORT).show(); Toast.makeText(ActivityEarCapture.this, "No Camera", Toast.LENGTH_SHORT).show();
} }
} }
}); });
if(this.getLastNonConfigurationInstance() != null) { if(this.getLastNonConfigurationInstance() != null) {
...@@ -114,31 +123,10 @@ public class ActivityEarCapture extends Activity { ...@@ -114,31 +123,10 @@ public class ActivityEarCapture extends Activity {
if(location == null || !location.exists()) { if(location == null || !location.exists()) {
location = null; location = null;
} else { } else {
String path = location.getAbsolutePath();
EarIdentifier identifier = new EarIdentifier(null);
Intent intent = new Intent("com.auriclon.activity_sift"); Intent intent = new Intent("com.auriclon.activity_sift");
File file = new File(location.getAbsolutePath() + ".jpg"); intent.putExtra("image_path", path);
InputStream input = null;
OutputStream output = null;
try {
input = new FileInputStream(location);
output = new FileOutputStream(file);
byte[] buf = new byte[1024];
int bytesread;
while ((bytesread = input.read(buf)) > 0) {
output.write(buf, 0, bytesread);
}
} catch(IOException e) {
e.printStackTrace();
} finally {
try {
input.close();
output.close();
} catch(Exception e) {
e.printStackTrace();
}
}
intent.putExtra("image_path", file);
startActivity(intent); startActivity(intent);
} }
} }
...@@ -167,4 +155,5 @@ public class ActivityEarCapture extends Activity { ...@@ -167,4 +155,5 @@ public class ActivityEarCapture extends Activity {
public Object onRetainNonConfigurationInstance() { public Object onRetainNonConfigurationInstance() {
return this; return this;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment