Using the camera on the Android device can be done via the integration of existing camera application. In this case you would start the existing Camera application via an intent and use the return data of the application to access the result .
One more we can do it same work using Camera API this process little bit difficult. Today i am going to explain using Intent before going start i have few questions
what is intent ?
what is return type?
where it will return?
Once are you above questions you can easily understand my post
Following is my source codes of Androidphoto project it works successfully
PhotoActivity.java
package com.vamsi.androidphoto;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class PhotoActivity extends Activity {
private Button photo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photo);
photo =(Button)findViewById(R.id.photo);
photo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// we will handle the returned data in onActivityResult
startActivityForResult(captureIntent,1);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("PhotoActivity", "onActivityResult");
}
}
The above class when they press button it will open camera activity next after taking photo it will come back onActivityResult . This onActivityResult have three parameters first one requestcode this code will sent when ever we start intent currently this code is 1 and resultCode is photo capture is successfully or not and data is for parsing photo like we can convert as bitmap or we can store a file in sdcard but currently i printing log message that place what ever you want do operation.
activity_photo.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="@+id/photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="144dp"
android:text="Photo" />
</RelativeLayout>
This my layoutfile of my project this layout file i used one button when ever user press it will open capture activity.
For doing above operation we need some permissions in manifest file
<uses-permission android:name="android.permission.CAMERA"/>
Thank you studying my blog-spot you have any doubts please post comment section .
No comments:
Post a Comment