Wednesday, May 21, 2014

Android : how to check if device has camera

In Android, you can use  PackageManager hasSystemFeature()  method to check if a device has camera, gps or other features.

See full example of using  PackageManager  in an activity class.

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
public class FlashLightActivity extends Activity {
 public void onCreate(Bundle savedInstanceState) {
  Context context = this;
  PackageManager packageManager = context.getPackageManager();
  // if device support camera?
  if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
   Log.i("camera", "This device has camera!");
   Log.i("camera", "This device has no camera!");

Camera flashlight example

You may interest on this example – How to turn on/off camera LED/flashlight in Android.

No comments:

Post a Comment