Hear i am going to explain how you can take a picture using camera intent , hear i put tow file code one is layout file and another is code file .
activity_demo.xml //it is layout file
activity_demo.xml //it is layout file
<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"> <ImageView
android:id="@+id/imgview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="@+id/bt1"/>
<Button
android:id="@+id/bt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Launch Camera"
android:onClick="launchCamera"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" /> </RelativeLayout>
Demo.java //it is class file
package com.dhaval.demo.activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.support.v7.app.ActionBarActivity; import android.view.Menu; import android.view.View; import android.widget.ImageView; import ccom.dhaval.demo.R; public class demo extends ActionBarActivity { private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 10; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_demo); } public void launchCamera(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) { if (resultCode == RESULT_OK) { ImageView imgView = (ImageView) findViewById(R.id.imgview); Uri imgUri = data.getData(); imgView.setImageURI(imgUri); } else if (resultCode == RESULT_CANCELED) { } else { } } } public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_create_pd, menu); return true; } }
No comments:
Post a Comment