【问题标题】:Capture image with stock camera an display in webview使用库存相机捕获图像并在 webview 中显示
【发布时间】:2012-07-03 17:19:31
【问题描述】:

我正在尝试使用 onClickListener 启动到 android 相机并拍摄一张照片,该照片将保存到 sdcard 上的特定文件夹中,然后在 webview 中显示捕获的图像。 到目前为止,这是我的代码。

private static final int CAMERA_REQUEST = 1888;
WebView WV;
Button capture;
Uri mCapturedImageURI;






@Override
public void onCreate(Bundle savedInstanceState) {



    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    this.WV =(WebView) this.findViewById(R.id.webView1);

    this.capture =(Button) findViewById(R.id.button1);


    capture.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {


             String fileName = "temp.jpg";  
                ContentValues values = new ContentValues();  
                values.put(MediaStore.Images.Media.TITLE, fileName);

                mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);  


            Intent cameraIntent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);
             cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, 
                     Uri.fromFile(new File( "sdcard/image")));  



             startActivityForResult(cameraIntent, CAMERA_REQUEST);


        }
    });

}
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  

     super.onActivityResult( requestCode, resultCode,  data);

     if (requestCode == CAMERA_REQUEST) {

         setContentView(R.id.webView1);
         WV.getSettings().setAllowFileAccess(true);
         WV.getSettings().setJavaScriptEnabled(true);
         WV.getSettings().setBuiltInZoomControls(true);
         String html = ("<html>" +
                "<head>" +
                "</head>" +
                "<body>" +
                "<img src=\"sdcard/temp.jpg\" alt=\"alternativo\" />" +
                "</body>" +
                "</html>"
                );
         WV.loadDataWithBaseURL("", html, "text/html", "utf-8", "");


     }

    }     


}

【问题讨论】:

  • 好的.....有什么问题......
  • 如果您正在写入 SD 卡,请确保在清单中包含 android.permission.WRITE_EXTERNAL_STORAGE。

标签: android webview camera android-camera-intent


【解决方案1】:

您只能使用 putExtra() 传递原始数据类型(String、int、float 等)。

以下是可以帮助您的文档:

http://developer.android.com/reference/android/content/Intent.html

如果要传递其他数据,使用Parcelable接口

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    • 2011-09-03
    • 2018-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多