Android Open Source - android-camera-example Camera Through Intent






From Project

Back to project page android-camera-example.

License

The source code is released under:

GNU General Public License

If you think the Android project android-camera-example listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
* Copyright 2013 Devaholic, Inc.  All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*/*from  w  w  w  . j  ava2 s  .co m*/
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*/
package com.devaholic.android.activities.camera;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.devaholic.android.R;

import roboguice.activity.RoboActivity;
import roboguice.inject.ContentView;
import roboguice.inject.InjectView;

/**
 * <h1>CameraThroughIntent</h1>
 *
 * <p>
 * Activity design to rely on an Android App to use the Camera
 * </p>
 *
 * @author M. Rabie Hayoun
 * @version 1
 * @since 1
 */
@ContentView(R.layout.camera_throught_intent_activity)
public class CameraThroughIntent extends RoboActivity {

    /**
     * Id of the onresult picture
     */
    private static final int CAMERA_PIC_REQUEST = 0;

    /**
     * Injecting the element where we are going to display the picture
     */
    @InjectView(R.id.imgPreviewIntent)
    ImageView imgView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    /**
     * Method that handles click event on button
     * @param view reference to the view that triggered the event
     */
    public void startCameraIntent(View view){
        Intent camera_intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(camera_intent, CameraThroughIntent.CAMERA_PIC_REQUEST);
    }

    /**
     * Method that handles all the callbacks from external application back to our application
     * @param requestCode Code associated with the action that just finished
     * @param resultCode Code that indicated how the action goes
     * @param data result get back from the external application
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch(requestCode){
            case CAMERA_PIC_REQUEST:
                if(resultCode==RESULT_OK){
                    Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
                    imgView.setImageBitmap(thumbnail);
                }
        }
    }


}




Java Source Code List

com.devaholic.android.activities.HomeActivity.java
com.devaholic.android.activities.SplashScreenActivity.java
com.devaholic.android.activities.camera.CameraThroughAPI.java
com.devaholic.android.activities.camera.CameraThroughIntent.java
com.devaholic.android.cameraControls.CameraSurface.java