Application : Capturing Image Using Mobile Camera And Showing It To User.
1.Activity_main.xml
Design :
Code :
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link] android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="145dp" />
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:id="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="67dp" />
</RelativeLayout>
CAMERA APP 1
1. [Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
Button bt;
ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
iv = (ImageView)findViewById([Link]);
bt = (Button)findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent in = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(in, 0);
}
});
}
protected void onActivityResult(int requestcode, int resultCode, Intent
data){
[Link](requestcode, resultCode, data);
Bitmap bp = (Bitmap)[Link]().get("data");
[Link](bp);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate([Link].menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in [Link].
int id = [Link]();
//noinspection SimplifiableIfStatement
if (id == [Link].action_settings) {
return true;
}
return [Link](item);
}
}
CAMERA APP 2