使用三星Galaxy标签中的默认相机拍照

时间:2011-08-10 14:04:43

标签: android

如何使用android中的默认相机为三星galaxy tab拍照?

我尝试过以下内容,但它无效。

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();

                        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);
            }
        }
        }

在galaxy选项卡中,所有相机图像都存储在相机文件夹中。如何获得最新图像?

0 个答案:

没有答案