Reputation: 11
I'm new at this. Go easy.
My code so far looks like this.
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.hardware.Camera;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String fmode = "Not Supported";
Camera cam = Camera.open();
Camera.Parameters p = cam.getParameters();
if (p.getFlashMode() != null)
{fmode = p.getFlashMode();}
TextView tv = new TextView(this);
tv.setText(fmode);
setContentView(tv);
}
}
When I run the program, I get the message stating that The application has stopped unexpectedly. Please try again. If I comment out these four lines...
//Camera cam = Camera.open();
//Camera.Parameters p = cam.getParameters();
//if (p.getFlashMode() != null)
//{fmode = p.getFlashMode();}
then the code runs fine and I get the "Not Supported" message. Then if I uncomment the first line where I declare the Camera object, it crashes again.
Feel free to be verbose, I'm in learning mode and would like all the information I can get. Thanks in advance.
Upvotes: 1
Views: 129
Reputation: 10800
Permissions are needed to allow access to certain features in android. Did you put <uses-permission android:name="android.permission.CAMERA" />
in your android manifest to have access to the camera.
Upvotes: 0
Reputation: 8158
Any chance you missed adding the camera permission in your AndroidManifest?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<application ...>
.
.
.
</application>
</manifest>
If that's not the case:
Why does the android emulator camera stop unexpectedly?
Upvotes: 1
Reputation: 724
I'm not very familiar using a camera in apps but I found you a great tutorial that can help you on your way towards your solution.
I hope this is helpful for you and may you find what you need :) if not, I'll make a test app myself and help you further
And like someone else stated above, some permissions must be added to use the camera, you can find those here: http://developer.android.com/reference/android/hardware/Camera.html
Upvotes: 0