想要使用Nativey调用原生拍照对像内的拍照。原生代码片段如下:
camera.takePicture(null, null, picture);
对于picture,定义如下:
private Camera.PictureCallback picture = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
ByteArrayInputStream bais = new ByteArrayInputStream(data);
Drawable d = BitmapDrawable.createFromStream(bais, Environment
.getExternalStorageDirectory().getAbsolutePath()
+ "/img.jpeg");
try {
File dir = new File(Environment.getExternalStorageDirectory()
.toString() + "/Villean/");
if (!dir.exists()) {
dir.mkdirs();
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmms",
Locale.CHINA).format(new Date());
File file = new File(dir.getPath() + "/" + timeStamp
+ "TouPai.jpg");
FileOutputStream outStream = new FileOutputStream(file);
outStream.write(data);
outStream.close();
control = true;
camera.startPreview();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
l.setBackgroundDrawable(d);
}
};
以上为android原生代码。
现在想要使用Navite实现,代码如下:
function androidAutoCamera() {
// Android平台导入Camera类
var Camera = plus.android.importClass("android.hardware.Camera");
// 创建Camera的实例对象
var camera = Camera.open(0);
//camera.setDisplayOrientation(90);
var pickCallBack = plus.android.implements("android.hardware.Camera.PictureCallback", {
"onPictureTaken": function(data,tcamera) {
alert('1');
}
});
alert('piccallback:'+pickCallBack);
plus.android.invoke(camera, "takePicture",null, null,pickCallBack);
alert(camera);
}
但是alert('1')的代码并未能触发,还请帮忙看看这样的方式调用回调是不是不正确的。在示例代码中并未查到这种复杂调用的参数的示例 。