如何创建所有android设备通用的照相机操作

in my app i want use the camera for capturing image and send to a server.

When the user opens the Camera part of my app, i want to show him the default camera of the device he is using. At present following is the two line code which i am using to capture image

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
 startActivityForResult(intent, TAKE_RECEIPT);

When i run this code in a HTC device, after capturing the image it showed a preview of the image with a done and retake button. When i click done it moves to the previous activity.

when i use the code in a moto device, after capturing the image it showed a preview of the image with a insert, retake and cancel. When i click done it moves to the previous activity.

Like this it will be differing for all devices. So when i click the done or insert or any other button positive button of any devices i want to start the uploading process.

How to proceed this please help me....

#0

You can use below code to solve your problem...

protected void startCameraActivity() 

{

    // TODO Auto-generated method stub
        Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
        intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );

        startActivityForResult( intent, 0 );
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    {   
        switch( resultCode )
        {
            case 0:
                break;

            case -1:
                onPhotoTaken();
                break;
        }
    }

    protected void onPhotoTaken()
    {

        ///write code here what you want to done after capture the image using device camera
    }

    @Override 
    protected void onRestoreInstanceState( Bundle savedInstanceState)
    {
        if( savedInstanceState.getBoolean( add_project1.PHOTO_TAKEN ) ) 
        {
            onPhotoTaken();
        }
    }

    @Override
    protected void onSaveInstanceState( Bundle outState ) 
    {
        outState.putBoolean( add_project1.PHOTO_TAKEN, _taken );
    }

#1

I'm not sure if the question is only about how to upload the image after the capture.. but if it is just it, I'll provide you a solution to handle it after you get back from the capture intent to your activity.

You can specify a path to save your image when you start the capture intent:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), "image.jpg");
outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_RECEIPT);

You can then handle the upload in your onActivityResult:

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

    if (requestCode == TAKE_RECEIPT) {
        if (resultCode == Activity.RESULT_OK) {             
                // user took a picture, upload it
                // outputFileUri contains the uri to your file
                // you should delete it when the upload completes

        } else if (resultCode == Activity.RESULT_CANCELED) {
                //user canceled - do nothing
        }
    }
}

#2

Actually the problem Arrives when we run this code on the Google nexus 1 device as it captures the images then when we click the done button exception arises..that is null pointer in Uri SelectedImage = data.getData();

推荐文章

用moq测试ria服务认证

用moq测试ria服务认证

推荐文章

从两个应用程序访问同一个sql lite数据库

从两个应用程序访问同一个sql lite数据库

推荐文章

大型对象未找到WCF错误

大型对象未找到WCF错误

推荐文章

我应该用窗口变量还是var?

我应该用窗口变量还是var?

推荐文章

sql server 2008分区列

sql server 2008分区列

推荐文章

管理IO monad

管理IO monad

推荐文章

如何用mini-Lab 1008 usb和LabVIEW控制直流电动机

如何用mini-Lab 1008 usb和LabVIEW控制直流电动机

推荐文章

组合子查询和联接的MySQL语句不起作用

组合子查询和联接的MySQL语句不起作用

推荐文章

我不明白这个单元测试是如何失败的

我不明白这个单元测试是如何失败的

推荐文章

为什么会这样?

为什么会这样?

推荐文章

在C++中初始化这样的地图会更好吗?

在C++中初始化这样的地图会更好吗?

推荐文章

创建显示维度与内容维度不同的div

创建显示维度与内容维度不同的div

推荐文章

在mysql插入之前清理数组值

在mysql插入之前清理数组值

推荐文章

拆分带有前缀的大型.gz文件

拆分带有前缀的大型.gz文件

推荐文章

在RVM中运行Rails应用程序时出错:“无法打开库”

在RVM中运行Rails应用程序时出错:“无法打开库”

推荐文章

Ruby on Rails中的表单

Ruby on Rails中的表单