我有一個混合的應用程序,它打開android的本機相機。 我的代碼:相機功能不顯示圖像
public class CameraFunActivity extends Activity {
OpenCamera openCamera;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webView=(WebView)findView ById(R.id.webkitWebView1);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setDatabaseEnabled(true);
openCamera=new OpenCamera(webView,CameraFunActivity.this);
webView.addJavascriptInterface(openCamera,"camera");
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode== 0 && resultCode == Activity.RESULT_OK){
System.out.println("!!!!!!!!!!!!!!!!!!!!Camera Working...........");
String imagePath = "file:/"+openCamera.getPath();
System.out.println("Image Pathhhhhhhhhh :::::::::::: " + imagePath);
openCamera.setPath(imagePath);
.. }
HTML: 功能captureImage1(){ camera.startCamera(); var path =「file://」+ camera.getPath(); // alert(path); document.getElementById(「image1」)。src = path; }
公共OpenCamera(web視圖APPVIEW,活動上下文){
this.mAppView = appView;
this.context = context; }
public void setPath(String path){
_path=path;
}
public String getPath(){
return _path;
}
public void setBitmap(Bitmap bitmap){
System.out.println("setting bitmap");
this.bitmap=bitmap;
}
public Bitmap getBitmap(){
System.out.println("getting bitmap");
return bitmap;
}
public void startCamera(){
/*
Camera camera = Camera.open();
Camera.Parameters parameters = camera.getParameters();
parameters.setPictureFormat(PixelFormat.JPEG);
camera.setParameters(parameters);*/
Date dt = new Date();
int date=dt.getDate();
int hours = dt.getHours();
int minutes = dt.getMinutes();
int seconds = dt.getSeconds();
String curTime = date+"_"+hours + "_"+minutes + "_"+ seconds;
_path=Environment.getExternalStorageDirectory() +"/"+curTime+".jpg";
File file = new File(_path);
Uri outputFileUri = Uri.fromFile(file);
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
// System.out.println("Paramssssssssssssss " + camera.getParameters().toString());
context.startActivityForResult(intent,0);
有時dispalays在img標籤src中的形象,有時沒有。需要幫助來找出問題。
另外,它是否與方向改變有關?
由於