title: What is missing in order to make my android camera flash turn on?
body: <p>I am trying to create a basic find my phone application and I'm running into a bit of an issue.  So far I am able to text a code word to my phone and have it play a song.  Next, I would like to be able to text a different key word and have it turn on the camera flash either in a steady light or pulsating. I have seen tons of example code so far but I can't figure out why it won't work for me.  </p>
  
  <p>I have included in my manifest permissions to access the camera and camera flash.
  I have tried both of the examples from this link <a href="https://stackoverflow.com/questions/6881004/setting-parameters-flash-mode-torch-doesnt-work-on-droid-x-2-3">Setting Parameters.FLASH_MODE_TORCH doesn&#39;t work on Droid X 2.3</a></p>
  
  <p>However several other options I have seen for turning on the camera flash on require entire classes instead of a small function.</p>
  
  <p>Here is the code I have so far:</p>
  
  <pre><code>import java.util.Timer;
  import java.util.TimerTask;
  import android.app.Activity;
  import android.content.BroadcastReceiver;
  import android.content.ContentResolver;
  import android.content.ContentValues;
  import android.content.Context;
  import android.content.Intent;
  import android.content.pm.PackageManager;
  import android.graphics.Camera;
  import android.hardware.*;
  import android.hardware.Camera.Parameters;
  import android.media.MediaPlayer;
  import android.net.Uri;
  import android.os.Bundle;
  import android.telephony.SmsMessage;
  import android.widget.Toast;
  
  public class SmsReceiver extends BroadcastReceiver {
  
      public static final String SMS_EXTRA_NAME = "pdus";
      public static final String SMS_URI = "content://sms";
  
      public void onReceive(Context context, Intent intent) {
          // Get SMS map from Intent
          Bundle extras = intent.getExtras();
  
          String messages = "";
  
          if (extras != null) {
              // Get received SMS array
              Object[] smsExtra = (Object[]) extras.get(SMS_EXTRA_NAME);
  
              // Get ContentResolver object for pushing encrypted SMS to incoming
              // folder
              ContentResolver contentResolver = context.getContentResolver();
  
              for (int i = 0; i &lt; smsExtra.length; ++i) {
                  SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]);
  
                  String body = sms.getMessageBody().toString();
                  String address = sms.getOriginatingAddress();
  
                  messages += "SMS from " + address + " :\n";
                  messages += body + "\n";
  
              }
  
              // Display SMS message
              Toast.makeText(context, "WE GOT A MESSAGE", Toast.LENGTH_SHORT)
                      .show();
  
              // plays eye of the tiger for 45 seconds
              if (messages.contains("Hey Sarah")) {
                  final MediaPlayer mp = MediaPlayer.create(context,
                          R.raw.sound_file_1);
                  mp.start();
  
                  // play ring tone for 45 seconds
                  new Timer().schedule(new TimerTask() {
                      @Override
                      public void run() {
                          mp.stop();
                      }
                  }, 45000);
              }
  
              //turn the flash on 
              if (messages.contains("Hey Geoff")) {
  
                  Camera mCamera = Camera.open();
                  mCamera.startPreview();
                  Camera.Parameters params = mCamera.getParameters();
                  if (params.getFlashMode() != null) {
                          params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
                  }
                  mCamera.setParameters(params);
              }
          }
      }
  }
  </code></pre>
  
  <p>It appears there are issues with camera.open() (the error: The method open() is undefined for the type Camera)
  with startPrevies() (the error: add cast to mCamera)
  with Camera.Parameters (the error: Camera.Parameters cannot be resolved to a type)
  Etc.</p>
  
  <p>Is the issue that this code snippet is trying to access android.graphics.Camera instead of android.hardware.Camera?  I am brand new to android so it's been a steep learning curve for me.  </p>