-1

Here is my code.Please help me i want turn on/off every x second.How can i make it?Please give me idea.

Im calling turn on/off codes with Methods. I tried loops but didnt work. Here is my code.Please help me i want turn on/off every x second.How can i make it?Please give me idea.

Im calling turn on/off codes with Methods. I tried loops but didnt work.

 package com.example.arama;

  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.content.pm.PackageManager;
  import android.hardware.Camera;
  import android.hardware.Camera.Parameters;
  import android.telephony.TelephonyManager;
 import android.view.View;
   import android.widget.Toast;

  public class GelenArama extends BroadcastReceiver{
private Camera cmobj;
private Intent intent;
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
Parameters p = cmobj.getParameters();

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub

    try {

         String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);

         if(state.equals(TelephonyManager.EXTRA_STATE_RINGING))
        {

             flashCalistir();




             // Your Code
        }

        if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
        {

                 // Your Code
        }

        if (state.equals(TelephonyManager.EXTRA_STATE_IDLE))
        {

         flashDurdur();

        }


    } catch (Exception e) {
        // TODO: handle exception
    }





        }   




    public void flashCalistir(){
        cmobj=Camera.open();
        Parameters p = cmobj.getParameters();
        p.setFlashMode(Parameters.FLASH_MODE_TORCH);
        cmobj.setParameters(p);
        cmobj.startPreview();

    }

    public void flashDurdur(){
        cmobj=Camera.open();
        Parameters p = cmobj.getParameters();
        p.setFlashMode(Parameters.FLASH_MODE_TORCH);
        cmobj.setParameters(p);
        cmobj.stopPreview();
        cmobj.release();
    }




   }
Curtis Shipley
  • 7,990
  • 1
  • 19
  • 28

1 Answers1

0

This answer describes how to turn the light on in lots of detail. How to turn on camera flash light programmatically in Android?

To turn it off and on, you could use a Timer and TimerTask.

Community
  • 1
  • 1
Curtis Shipley
  • 7,990
  • 1
  • 19
  • 28