-1

onClickListener を使用して Android カメラを起動し、SD カードの特定のフォルダーに保存する写真を撮り、キャプチャした画像を 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", "");


     }

    }     


}
4

1 に答える 1

0

putExtra() で渡すことができるのは、プリミティブ データ型 (String、int、float など) のみです。

これに役立つドキュメントは次のとおりです。

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

他のデータを渡したい場合は、Parcelableインターフェイスを使用します

于 2012-07-03T18:53:14.793 に答える