Checking if camera presents in Android device

Today I tried some ideas with camera in Android and found that there is an easy way to check if camera presents in Android device. Here I am going to show example which shows how to check it.
Example:

import android.app.Activity;import android.os.Bundle;import android.util.Log;public class Main extends Activity{private static String APP_TAG = "tag";private android.hardware.Camera camera;@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);try{camera = android.hardware.Camera.open()} catch (Exception e){Log.e(APP_TAG,e.getMessage())}}}

Note:don’t forget to add

<uses-feature android:name="android.hardware.camera" android:required="false"/>

and

<uses-permission android:name="android.permission.CAMERA" />

in AndroidManifest.xml file.

 

If you’d like to get the latest posts as soon as they’re published,subscribe to our feed!

Share

No related posts.

Leave a Reply

  

  

  

You can use these HTML tags

<a href=""title=""><abbr title=""><acronym title=""><b><blockquote cite=""><cite><code><del datetime=""><em><i><q cite=""><strike><strong>

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna,tincidunt vitae molestie nec,molestie at mi. Nulla nulla lorem,suscipit in posuere in,interdum non magna.