开发者

Taking a picture using the default camera in samsung galaxy tab

How can I take a picture using the default camera in android for samsung galaxy tab?

I have tried the following, but it's not working.

public void takePhoto(View v) {


        //Object capturedImageFilePath = null;
        String fileName = System.currentTimeMillis()+"";
        //create parameters for Intent with filename
        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, fileName);
        values.put(MediaStore.Images.Media.DESCRIPTION,"Image capture by camera");
        //imageUri is the current activity attribute, define and save it for later usage (also in onSaveInstanceState)
        imageUri = getContentResolver().insert(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        //create new Intent
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
         intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);


        startActivityForResult(intent, IMAGE_CAPTURE);


    }


protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == IMAGE_CAPTURE) {
            if (resultCode == RESULT_OK) {
                //use imageUri here to access the image
                 String[] projection = { MediaStore.Images.Media.DATA}; 
                    Cursor cursor = managedQuery(imageUri, projection, null, null, null); 
                    Toast.makeText(CameraActivity.this,cursor.toString(),Toast.LENGTH_LONG).show();

                    int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
                    Toast.makeText(CameraActivity.this,Integer.toString(column_index_data),Toast.LENGTH_LONG).show();


                    cursor.moveToFirst(); 
                    String capturedImageFilePath = cursor.getString(column_index_data);
                     Toast.makeText(CameraActivity.this,capturedImageFilePath , Toast.LENGTH_LONG).show();

                   /* File imageFile = new File(capturedImageFilePath);
                    if(imageFile.exists()){*/
                        Bitmap bm = BitmapFactory.decodeFile(capturedImageFilePath);
                        imageView=(ImageView)findViewById(R.id.img);
                        Toast.makeText(CameraActivity.this,"imageview"+imageView.toString() , Toast.LENGTH_LONG).show();
开发者_如何学C
                        imageView.setImageBitmap(bm);}
            //} 

            else if (resultCode == RESULT_CANCELED) {
                Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT);
            } else {
                Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT);
            }
        }
        }

In galaxy tab, all camera images are stored in the camera folder. How to get the latest image?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜