针对Phonegap的AR插件

时间:2013-07-01 15:40:12

标签: cordova phonegap-plugins augmented-reality

我正在尝试使用此功能创建一个phonegap插件 -

https://github.com/dixon1e/ARviewer-phoneGap

我在我的插件操作方法中使用此调用 -

if(action.equalsIgnoreCase("open")) {  
// campreview.onCreate(null);  
Log.d(PLUGIN_NAME, "Inside Open");  
cordova.getActivity().runOnUiThread(new Runnable(){   
public void run() {  
Log.d(PLUGIN_NAME, "Start Camera");  
Context context = cordova.getActivity().getApplicationContext();  
Intent intent = new Intent(context,CameraActivity.class);  
cordova.getActivity().startActivity(intent);  
callbackContext.success();  
}  
});  

我创建了一个像这样的CameraActivity.java文件 -

private final static String tag = "CameraActivity";  
@Override  
public void onCreate(Bundle savedInstanceState) {  
Log.d(tag, "Inside onCreate CameraActivity");  

super.onCreate(savedInstanceState);   

//  arviewer.arurl();  
setContentView(R.layout.main);  
RelativeLayout preview = (RelativeLayout)findViewById(R.id.phonegap_container);  

// Create an instance of Camera  
//mCamera = getCameraInstance();  
if(!getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {  
Toast.makeText(this, "No Camera on this Device", Toast.LENGTH_LONG).show();  
} else {  
cameraID = findBackFacingCamera();  
if(cameraID == 0){  
    mCamera = Camera.open(cameraID);  
} else {  
    Toast.makeText(this, "No Back Camera Found", Toast.LENGTH_LONG).show();  
}  

}  

// Create our Preview view and set it as the content of our activity.  
mPreview = new CameraSurfacePreview(this, mCamera);  
preview.setBackgroundColor(Color.TRANSPARENT);  
preview.addView(mPreview);  
preview.setFocusable(false);  
/*  FrameLayout preview = (FrameLayout) findViewById(R.id.phonegap_container);  
preview.setBackgroundColor(Color.TRANSPARENT);  
preview.addView(mPreview);  
preview.setFocusable(false); */  

}  

private int findBackFacingCamera() {  
int cameraId = -1;  
// Search for the Back facing camera  
int numberOfCameras = Camera.getNumberOfCameras();  
for (int i = 0; i < numberOfCameras; i++) {  
CameraInfo info = new CameraInfo();  
Camera.getCameraInfo(i, info);  
if (info.facing == CameraInfo.CAMERA_FACING_BACK) {  
Log.d(tag, "Camera found, cameraID =" +i);  
cameraId = i;  
break;  
}  
}  
return cameraId;  
}  
}  

运行后代码相机在预览模式下打开,但是没有显示显示POI的webview数据,当我按后退键然后显示Webview数据时。我想我必须在我的onCreate函数中添加以下代码来解决这个问题,但是我将如何添加此代码。如果我尝试添加它,则显示appView未声明。

View html = (View)appView.getParent();  
html.setBackgroundColor(Color.TRANSPARENT);  
view.addView(html, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));  
appView.setBackgroundColor(Color.TRANSPARENT);  
// Avoid the focus on click events  
appView.setFocusable(false);  

1 个答案:

答案 0 :(得分:0)

我建议你为你的项目使用wikitude SDK。

http://www.wikitude.com/products/wikitude-sdk/