You'll probably want to start a new Android project and then import the CameraPreview.java file into your package namespace under your project's src folder.
Once you do that you'll see you have some errors, so let's clean those up.
Let's start by first retrieving the camera_menu.xml file from the ApiDemos project res/menu folder and importing that into our res/layout folder. This is the menu that will display when you hit the menu key.
We're still missing some strings, so let's add the missing strings from res/values/strings.xml to our res/values/strings.xml file.
<string name="density_title">Density: Unknown Screen</string> <string name="camera_alert">Device has only one camera!</string> <string name="switch_cam">Switch Camera</string>
Finally we'll change the location for our camera_menu to it's new location. Change line 109 to
We've now cleaned up all the errors (hopefully)! But if you launch your new project you'll notice nothing special happens. That's because we haven't called our new CameraPreview activity that we were so careful to import.inflator.inflate(R.layout.camera_menu, menu);
Let's add a call in the onCreate() method of our main activity
and then add this activity to our AndroidManifest.xmlstartActivity(new Intent(this, CameraPreview.class));
If we launched out activity now, we'd still be jumping the gun and would get a force close. The last thing we should (which probably should have been first!) is to add permission to use the camera by adding this line to our AndroidManifest.xml<activity android:name=".CameraPreview"></activity>
Now if you launch your new sample app you should see the camera preview. Now you're free to tinker as you'd like without disturbing your original copy of the ApiDemos code.<uses-permission android:name="android.permission.CAMERA" />