mirror of
https://github.com/apache/cordova-android.git
synced 2025-04-01 04:15:04 +08:00
Adding Preliminary Camera Support for Android in PhoneGap.
(Note: This has not been tested yet)
This commit is contained in:
parent
9574e509e2
commit
65b401d477
37
src/com/nitobi/phonegap/CameraHandler.java
Normal file
37
src/com/nitobi/phonegap/CameraHandler.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package com.nitobi.phonegap;
|
||||||
|
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
|
import android.hardware.Camera;
|
||||||
|
import android.hardware.Camera.PictureCallback;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
|
||||||
|
public class CameraHandler implements PictureCallback{
|
||||||
|
|
||||||
|
|
||||||
|
private OutputStream oStream;
|
||||||
|
BitmapFactory photoLab;
|
||||||
|
|
||||||
|
CameraHandler(OutputStream output)
|
||||||
|
{
|
||||||
|
oStream = output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPictureTaken(byte[] graphic, Camera arg1) {
|
||||||
|
try {
|
||||||
|
oStream.write(graphic);
|
||||||
|
oStream.flush();
|
||||||
|
oStream.close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//TO-DO: Put some logging here saying that this epic failed
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do some other things, like post it to a service!
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
52
src/com/nitobi/phonegap/CameraListener.java
Normal file
52
src/com/nitobi/phonegap/CameraListener.java
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package com.nitobi.phonegap;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.hardware.Camera;
|
||||||
|
import android.hardware.Camera.ShutterCallback;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.provider.MediaStore.Images.Media;
|
||||||
|
|
||||||
|
public class CameraListener implements ShutterCallback{
|
||||||
|
|
||||||
|
private Camera mCam;
|
||||||
|
private CameraHandler camHand;
|
||||||
|
private SimpleDateFormat timeStampFormat = new SimpleDateFormat("yyyyMMddHHmmssSS");
|
||||||
|
private Context mCtx;
|
||||||
|
private Uri target = Media.EXTERNAL_CONTENT_URI;
|
||||||
|
|
||||||
|
CameraListener(Context ctx){
|
||||||
|
mCam = Camera.open();
|
||||||
|
mCtx = ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void snap()
|
||||||
|
{
|
||||||
|
String filename = timeStampFormat.format(new Date());
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(Media.TITLE, filename);
|
||||||
|
values.put(Media.DESCRIPTION, "PhoneGap");
|
||||||
|
Uri uri = mCtx.getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
OutputStream output = (OutputStream) mCtx.getContentResolver().openOutputStream(uri);
|
||||||
|
camHand = new CameraHandler(output);
|
||||||
|
mCam.takePicture(this, null, camHand);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
/*TODO: Do some logging here */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onShutter() {
|
||||||
|
/* This is logged */
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user