Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can I get Some Help With Andriod Application...Eclipse Create a mini application

ID: 667766 • Letter: C

Question

Can I get Some Help With Andriod Application...Eclipse

Create a mini application that takes either an image file or a snap from the camera and display all the Meta-data information alongside the image. Make sure you include the image's Latitude and Longitude values. This metadata is called the EXIF data. For more information on EXIF data please reference the link below.

http://developer.android.com/reference/android/media/ExifInterface.html

As a reminder, when taking an image with the camera, you may use an ImageButton, which when pressed calls the Camera app, takes the picture, and then displays the image as the button's background.

Explanation / Answer

eclipse 4.2 juno

open eclipse and go to file -->new -->project

Go to android application

specify the name of the application

next

after that create activity should be checked

choose the location

next

choose your icon for your app

next

create activity

blank activity

next

next

finish

you can see the structure of the program

create the android program for camera app

by creating a xml file

<?xml version="1.0" encoding="utf-8"?>
02
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
03
android:layout_width="fill_parent"
04
android:layout_height="fill_parent"
05
android:orientation="horizontal" >
06

07
<LinearLayout
08
android:id="@+id/camera_preview"
09
android:layout_width="fill_parent"
10
android:layout_height="fill_parent"
11
android:layout_weight="1"
12
android:orientation="horizontal"/>
13

14
<LinearLayout
15
android:id="@+id/buttonsLayout"
16
android:layout_width="wrap_content"
17
android:layout_height="match_parent"
18
android:layout_gravity="center"
19
android:orientation="vertical" >
20
<Button
21
android:id="@+id/button_ChangeCamera"
22
android:layout_width="72dp"
23
android:layout_height="wrap_content"
24
android:text="Switch Camera"
25
android:layout_marginTop="30dp"/>
26
<Button
27
android:id="@+id/button_capture"
28
android:layout_width="wrap_content"
29
android:layout_height="wrap_content"
30
android:text="Capture"
31
android:layout_marginTop="100dp"/>
32
</LinearLayout>
33
</LinearLayout>

After that creating a main program

001
package com.javacodegeeks.androidcameraexample;
002

003
import java.io.File;
004
import java.io.FileNotFoundException;
005
import java.io.FileOutputStream;
006
import java.io.IOException;
007
import java.text.SimpleDateFormat;
008
import java.util.Date;
009

010
import android.app.Activity;
011
import android.content.Context;
012
import android.content.pm.PackageManager;
013
import android.hardware.Camera;
014
import android.hardware.Camera.CameraInfo;
015
import android.hardware.Camera.PictureCallback;
016
import android.os.Bundle;
017
import android.view.View;
018
import android.view.View.OnClickListener;
019
import android.view.WindowManager;
020
import android.widget.Button;
021
import android.widget.LinearLayout;
022
import android.widget.Toast;
023

024
public class AndroidCameraExample extends Activity {
025
private Camera mCamera;
026
private CameraPreview mPreview;
027
private PictureCallback mPicture;
028
private Button capture, switchCamera;
029
private Context myContext;
030
private LinearLayout cameraPreview;
031
private boolean cameraFront = false;
032

033
@Override
034
public void onCreate(Bundle savedInstanceState) {
035
super.onCreate(savedInstanceState);
036
setContentView(R.layout.activity_main);
037
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
038
myContext = this;
039
initialize();
040
}
041

042
private int findFrontFacingCamera() {
043
int cameraId = -1;
044
// Search for the front facing camera
045
int numberOfCameras = Camera.getNumberOfCameras();
046
for (int i = 0; i < numberOfCameras; i++) {
047
CameraInfo info = new CameraInfo();
048
Camera.getCameraInfo(i, info);
049
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
050
cameraId = i;
051
cameraFront = true;
052
break;
053
}
054
}
055
return cameraId;
056
}
057

058
private int findBackFacingCamera() {
059
int cameraId = -1;
060
//Search for the back facing camera
061
//get the number of cameras
062
int numberOfCameras = Camera.getNumberOfCameras();
063
//for every camera check
064
for (int i = 0; i < numberOfCameras; i++) {
065
CameraInfo info = new CameraInfo();
066
Camera.getCameraInfo(i, info);
067
if (info.facing == CameraInfo.CAMERA_FACING_BACK) {
068
cameraId = i;
069
cameraFront = false;
070
break;
071
}
072
}
073
return cameraId;
074
}
075

076
public void onResume() {
077
super.onResume();
078
if (!hasCamera(myContext)) {
079
Toast toast = Toast.makeText(myContext, "Sorry, your phone does not have a camera!", Toast.LENGTH_LONG);
080
toast.show();
081
finish();
082
}
083
if (mCamera == null) {
084
//if the front facing camera does not exist
085
if (findFrontFacingCamera() 1) {
086
//release the old camera instance
087
//switch camera, from the front and the back and vice versa
088

089
releaseCamera();
090
chooseCamera();
091
} else {
092
Toast toast = Toast.makeText(myContext, "Sorry, your phone has only one camera!", Toast.LENGTH_LONG);
093
toast.show();
094
}
095
}
096
};
097

098
public void chooseCamera() {
099
//if the camera preview is the front
100
if (cameraFront) {
101
int cameraId = findBackFacingCamera();
102
if (cameraId >= 0) {
103
//open the backFacingCamera
104
//set a picture callback
105
//refresh the preview
106

107
mCamera = Camera.open(cameraId);
108
mPicture = getPictureCallback();
109
mPreview.refreshCamera(mCamera);
110
}
111
} else {
112
int cameraId = findFrontFacingCamera();
113
if (cameraId >= 0) {
114
//open the backFacingCamera
115
//set a picture callback
116
//refresh the preview
117

118
mCamera = Camera.open(cameraId);
119
mPicture = getPictureCallback();
120
mPreview.refreshCamera(mCamera);
121
}
122
}
123
}
124

125
@Override
126
protected void onPause() {
127
super.onPause();
128
//when on Pause, release camera in order to be used from other applications
129
releaseCamera();
130
}
131

132
private boolean hasCamera(Context context) {
133
//check if the device has camera
134
if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
135
return true;
136
} else {
137
return false;
138
}
139
}
140

141
private PictureCallback getPictureCallback() {
142
PictureCallback picture = new PictureCallback() {
143

144
@Override
145
public void onPictureTaken(byte[] data, Camera camera) {
146
//make a new picture file
147
File pictureFile = getOutputMediaFile();
148

149
if (pictureFile == null) {
150
return;
151
}
152
try {
153
//write the file
154
FileOutputStream fos = new FileOutputStream(pictureFile);
155
fos.write(data);
156
fos.close();
157
Toast toast = Toast.makeText(myContext, "Picture saved: " + pictureFile.getName(), Toast.LENGTH_LONG);
158
toast.show();
159

160
} catch (FileNotFoundException e) {
161
} catch (IOException e) {
162
}
163

164
//refresh camera to continue preview
165
mPreview.refreshCamera(mCamera);
166
}
167
};
168
return picture;
169
}
170

171
OnClickListener captrureListener = new OnClickListener() {
172
@Override
173
public void onClick(View v) {
174
mCamera.takePicture(null, null, mPicture);
175
}
176
};
177

178
//make picture and save to a folder
179
private static File getOutputMediaFile() {
180
//make a new file directory inside the "sdcard" folder
181
File mediaStorageDir = new File("/sdcard/", "JCG Camera");
182

183
//if this "JCGCamera folder does not exist
184
if (!mediaStorageDir.exists()) {
185
//if you cannot make this folder return
186
if (!mediaStorageDir.mkdirs()) {
187
return null;
188
}
189
}
190

191
//take the current timeStamp
192
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
193
File mediaFile;
194
//and make a media file:
195
mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");
196

197
return mediaFile;
198
}
199

200
private void releaseCamera() {
201
// stop and release camera
202
if (mCamera != null) {
203
mCamera.release();
204
mCamera = null;
205
}
206
}
207
}

after that create a android manifest

because it needs hardware camera also

<?xml version="1.0" encoding="utf-8"?>
02
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
03
package="com.javacodegeeks.androidcameraexample"
04
android:versionCode="1"
05
android:versionName="1.1" >
06

07
<uses-sdk
08
android:minSdkVersion="10"
09
android:targetSdkVersion="19" />
10

11
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
12
<uses-permission android:name="android.permission.CAMERA" />
13
<uses-feature android:name="android.hardware.camera" />
14
<uses-feature android:name="android.hardware.camera.autofocus" />
15
<uses-feature android:name="android.hardware.camera.front" android:required="false" />
16

17
<application
18
android:icon="@drawable/ic_launcher"
19
android:label="@string/app_name" >
20
<activity
21
android:name=".AndroidCameraExample"
22
android:label="@string/app_name"
23
android:screenOrientation="landscape"
24
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
25
<intent-filter>
26
<action android:name="android.intent.action.MAIN" />
27
<category android:name="android.intent.category.LAUNCHER" />
28
</intent-filter>
29
</activity>
30
</application>
31
</manifest>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote