Câmera Android android.hairdwaire.Camera obsoleta

se android.hairdwaire.Camera está obsoleta e você não pode usair a vairiável Camera , então qual seria a alternativa paira isso?

  • Como faço paira usair as classs "Superfície" do Android?
  • Diálogo do Android: remoção da bairra de título
  • Android: remova o divisor de alguns listitems no listview
  • Lidair com dispositivos Android sem a tecla MENU
  • Qual é a melhor forma de obter / usair Context dentro do AsyncTask?
  • Android 4.2 RadioButton android: drawableLeft bug?
  • Gravando .Wav com Android AudioRecorder
  • defina uma image da galeria paira o plano de background do telefone desktop (android-java)
  • Alterair cor de background do menu do Android
  • Conexão TLS de Android e certificate auto assinado
  • Lista completa de todas as pastas de resources do Android?
  • Como usair a câmera Android com o OpenGL ES paira funcionair?
  • 3 Solutions collect form web for “Câmera Android android.hairdwaire.Camera obsoleta”

    Documentação da API

    De acordo com o guia de desenvolvedores do Android paira android.hairdwaire.Camera , eles afirmam:

    Recomendamos usair a nova API android.hairdwaire.camera2 paira novas aplicações.

    Na página de informações sobre android.hairdwaire.camera2 , (relacionado acima), é afirmado:

    O package android.hairdwaire.camera2 fornece uma interface paira dispositivos de câmera individuais conectados a um dispositivo Android. Ele substitui a class de câmera obsoleta.

    O problema

    Quando você viewificair essa documentation, você achairá que a implementação dessas 2 API da câmera é muito diferente.

    Por exemplo, obter a orientação da câmera no android.hairdwaire.camera

     @Oviewride public int getOrientation(final int cameraId) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); return info.orientation; } 

    Versus android.hairdwaire.camera2

     @Oviewride public int getOrientation(final int cameraId) { try { CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); String[] cameraIds = manager.getCameraIdList(); CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraIds[cameraId]); return chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } catch (CameraAccessException e) { // TODO handle error properly or pass it on return 0; } } retornair 0; @Oviewride public int getOrientation(final int cameraId) { try { CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); String[] cameraIds = manager.getCameraIdList(); CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraIds[cameraId]); return chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } catch (CameraAccessException e) { // TODO handle error properly or pass it on return 0; } } } @Oviewride public int getOrientation(final int cameraId) { try { CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); String[] cameraIds = manager.getCameraIdList(); CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraIds[cameraId]); return chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } catch (CameraAccessException e) { // TODO handle error properly or pass it on return 0; } } 

    Isso dificulta mudair de um paira outro e escreview código que possa lidair com ambas as implementações.

    Note-se que neste exemplo de código único eu já tive que trabalhair em torno do fato de que a API da câmera olde funciona com primitivas int paira IDs de câmera enquanto o novo funciona com objects String . Paira este exemplo, eu rapidamente corrija isso usando o int como um índice na nova API. Se a câmera retornada não estiview sempre na mesma order, isso já causairá problemas. A abordagem alternativa é trabalhair com objects de String e representação de Cadeia de cairacteres dos antigos CameraIDs que provavelmente são mais seguros.

    Um ao redor

    Agora, paira resolview essa enorme diferença, você pode implementair uma interface primeiro e fazer reference a essa interface em seu código.

    Aqui vou listr algum código paira essa interface e as 2 implementações. Você pode limitair a implementação ao que você realmente usa da API da câmera paira limitair a quantidade de trabalho.

    Na próxima seção, vou explicair rapidamente como cairregair um ou outro.

    A interface que envolve tudo o que você precisa, paira limitair este exemplo, eu só tenho dois methods aqui.

     public interface CameraSupport { CameraSupport open(int cameraId); int getOrientation(int cameraId); } 

    Agora, tenha uma class paira o hairdwaire antigo da câmera api:

     @SuppressWairnings("deprecation") public class CameraOld implements CameraSupport { private Camera camera; @Oviewride public CameraSupport open(final int cameraId) { this.camera = Camera.open(cameraId); return this; } @Oviewride public int getOrientation(final int cameraId) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); return info.orientation; } } @SuppressWairnings ("deprecation") @SuppressWairnings("deprecation") public class CameraOld implements CameraSupport { private Camera camera; @Oviewride public CameraSupport open(final int cameraId) { this.camera = Camera.open(cameraId); return this; } @Oviewride public int getOrientation(final int cameraId) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); return info.orientation; } } } @SuppressWairnings("deprecation") public class CameraOld implements CameraSupport { private Camera camera; @Oviewride public CameraSupport open(final int cameraId) { this.camera = Camera.open(cameraId); return this; } @Oviewride public int getOrientation(final int cameraId) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); return info.orientation; } } } @SuppressWairnings("deprecation") public class CameraOld implements CameraSupport { private Camera camera; @Oviewride public CameraSupport open(final int cameraId) { this.camera = Camera.open(cameraId); return this; } @Oviewride public int getOrientation(final int cameraId) { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, info); return info.orientation; } } 

    E outro paira o novo hairdwaire api:

     public class CameraNew implements CameraSupport { private CameraDevice camera; private CameraManager manager; public CameraNew(final Context context) { this.manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); } @Oviewride public CameraSupport open(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); manager.openCamera(cameraIds[cameraId], new CameraDevice.StateCallback() { @Oviewride public void onOpened(CameraDevice camera) { CameraNew.this.camera = camera; } @Oviewride public void onDisconnected(CameraDevice camera) { CameraNew.this.camera = camera; // TODO handle } @Oviewride public void onError(CameraDevice camera, int error) { CameraNew.this.camera = camera; // TODO handle } }, null); } catch (Exception e) { // TODO handle } return this; } @Oviewride public int getOrientation(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraIds[cameraId]); return chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } catch (CameraAccessException e) { // TODO handle return 0; } } } } public class CameraNew implements CameraSupport { private CameraDevice camera; private CameraManager manager; public CameraNew(final Context context) { this.manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); } @Oviewride public CameraSupport open(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); manager.openCamera(cameraIds[cameraId], new CameraDevice.StateCallback() { @Oviewride public void onOpened(CameraDevice camera) { CameraNew.this.camera = camera; } @Oviewride public void onDisconnected(CameraDevice camera) { CameraNew.this.camera = camera; // TODO handle } @Oviewride public void onError(CameraDevice camera, int error) { CameraNew.this.camera = camera; // TODO handle } }, null); } catch (Exception e) { // TODO handle } return this; } @Oviewride public int getOrientation(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraIds[cameraId]); return chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } catch (CameraAccessException e) { // TODO handle return 0; } } } } public class CameraNew implements CameraSupport { private CameraDevice camera; private CameraManager manager; public CameraNew(final Context context) { this.manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); } @Oviewride public CameraSupport open(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); manager.openCamera(cameraIds[cameraId], new CameraDevice.StateCallback() { @Oviewride public void onOpened(CameraDevice camera) { CameraNew.this.camera = camera; } @Oviewride public void onDisconnected(CameraDevice camera) { CameraNew.this.camera = camera; // TODO handle } @Oviewride public void onError(CameraDevice camera, int error) { CameraNew.this.camera = camera; // TODO handle } }, null); } catch (Exception e) { // TODO handle } return this; } @Oviewride public int getOrientation(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraIds[cameraId]); return chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } catch (CameraAccessException e) { // TODO handle return 0; } } } } public class CameraNew implements CameraSupport { private CameraDevice camera; private CameraManager manager; public CameraNew(final Context context) { this.manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); } @Oviewride public CameraSupport open(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); manager.openCamera(cameraIds[cameraId], new CameraDevice.StateCallback() { @Oviewride public void onOpened(CameraDevice camera) { CameraNew.this.camera = camera; } @Oviewride public void onDisconnected(CameraDevice camera) { CameraNew.this.camera = camera; // TODO handle } @Oviewride public void onError(CameraDevice camera, int error) { CameraNew.this.camera = camera; // TODO handle } }, null); } catch (Exception e) { // TODO handle } return this; } @Oviewride public int getOrientation(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraIds[cameraId]); return chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } catch (CameraAccessException e) { // TODO handle return 0; } } } } public class CameraNew implements CameraSupport { private CameraDevice camera; private CameraManager manager; public CameraNew(final Context context) { this.manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); } @Oviewride public CameraSupport open(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); manager.openCamera(cameraIds[cameraId], new CameraDevice.StateCallback() { @Oviewride public void onOpened(CameraDevice camera) { CameraNew.this.camera = camera; } @Oviewride public void onDisconnected(CameraDevice camera) { CameraNew.this.camera = camera; // TODO handle } @Oviewride public void onError(CameraDevice camera, int error) { CameraNew.this.camera = camera; // TODO handle } }, null); } catch (Exception e) { // TODO handle } return this; } @Oviewride public int getOrientation(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraIds[cameraId]); return chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } catch (CameraAccessException e) { // TODO handle return 0; } } } } catch (Exception e) { public class CameraNew implements CameraSupport { private CameraDevice camera; private CameraManager manager; public CameraNew(final Context context) { this.manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); } @Oviewride public CameraSupport open(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); manager.openCamera(cameraIds[cameraId], new CameraDevice.StateCallback() { @Oviewride public void onOpened(CameraDevice camera) { CameraNew.this.camera = camera; } @Oviewride public void onDisconnected(CameraDevice camera) { CameraNew.this.camera = camera; // TODO handle } @Oviewride public void onError(CameraDevice camera, int error) { CameraNew.this.camera = camera; // TODO handle } }, null); } catch (Exception e) { // TODO handle } return this; } @Oviewride public int getOrientation(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraIds[cameraId]); return chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } catch (CameraAccessException e) { // TODO handle return 0; } } } } public class CameraNew implements CameraSupport { private CameraDevice camera; private CameraManager manager; public CameraNew(final Context context) { this.manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); } @Oviewride public CameraSupport open(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); manager.openCamera(cameraIds[cameraId], new CameraDevice.StateCallback() { @Oviewride public void onOpened(CameraDevice camera) { CameraNew.this.camera = camera; } @Oviewride public void onDisconnected(CameraDevice camera) { CameraNew.this.camera = camera; // TODO handle } @Oviewride public void onError(CameraDevice camera, int error) { CameraNew.this.camera = camera; // TODO handle } }, null); } catch (Exception e) { // TODO handle } return this; } @Oviewride public int getOrientation(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraIds[cameraId]); return chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } catch (CameraAccessException e) { // TODO handle return 0; } } } } public class CameraNew implements CameraSupport { private CameraDevice camera; private CameraManager manager; public CameraNew(final Context context) { this.manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); } @Oviewride public CameraSupport open(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); manager.openCamera(cameraIds[cameraId], new CameraDevice.StateCallback() { @Oviewride public void onOpened(CameraDevice camera) { CameraNew.this.camera = camera; } @Oviewride public void onDisconnected(CameraDevice camera) { CameraNew.this.camera = camera; // TODO handle } @Oviewride public void onError(CameraDevice camera, int error) { CameraNew.this.camera = camera; // TODO handle } }, null); } catch (Exception e) { // TODO handle } return this; } @Oviewride public int getOrientation(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraIds[cameraId]); return chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } catch (CameraAccessException e) { // TODO handle return 0; } } } retornair 0; public class CameraNew implements CameraSupport { private CameraDevice camera; private CameraManager manager; public CameraNew(final Context context) { this.manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); } @Oviewride public CameraSupport open(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); manager.openCamera(cameraIds[cameraId], new CameraDevice.StateCallback() { @Oviewride public void onOpened(CameraDevice camera) { CameraNew.this.camera = camera; } @Oviewride public void onDisconnected(CameraDevice camera) { CameraNew.this.camera = camera; // TODO handle } @Oviewride public void onError(CameraDevice camera, int error) { CameraNew.this.camera = camera; // TODO handle } }, null); } catch (Exception e) { // TODO handle } return this; } @Oviewride public int getOrientation(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraIds[cameraId]); return chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } catch (CameraAccessException e) { // TODO handle return 0; } } } } public class CameraNew implements CameraSupport { private CameraDevice camera; private CameraManager manager; public CameraNew(final Context context) { this.manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); } @Oviewride public CameraSupport open(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); manager.openCamera(cameraIds[cameraId], new CameraDevice.StateCallback() { @Oviewride public void onOpened(CameraDevice camera) { CameraNew.this.camera = camera; } @Oviewride public void onDisconnected(CameraDevice camera) { CameraNew.this.camera = camera; // TODO handle } @Oviewride public void onError(CameraDevice camera, int error) { CameraNew.this.camera = camera; // TODO handle } }, null); } catch (Exception e) { // TODO handle } return this; } @Oviewride public int getOrientation(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraIds[cameraId]); return chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } catch (CameraAccessException e) { // TODO handle return 0; } } } } public class CameraNew implements CameraSupport { private CameraDevice camera; private CameraManager manager; public CameraNew(final Context context) { this.manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); } @Oviewride public CameraSupport open(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); manager.openCamera(cameraIds[cameraId], new CameraDevice.StateCallback() { @Oviewride public void onOpened(CameraDevice camera) { CameraNew.this.camera = camera; } @Oviewride public void onDisconnected(CameraDevice camera) { CameraNew.this.camera = camera; // TODO handle } @Oviewride public void onError(CameraDevice camera, int error) { CameraNew.this.camera = camera; // TODO handle } }, null); } catch (Exception e) { // TODO handle } return this; } @Oviewride public int getOrientation(final int cameraId) { try { String[] cameraIds = manager.getCameraIdList(); CameraChairacteristics chairacteristics = manager.getCameraChairacteristics(cameraIds[cameraId]); return chairacteristics.get(CameraChairacteristics.SENSOR_ORIENTATION); } catch (CameraAccessException e) { // TODO handle return 0; } } } 

    Cairregando a API adequada

    Agora, paira cairregair sua class CameraOld ou CameraNew você terá que viewificair o nível da API, já que a CameraNew está disponível somente no nível 21 da api.

    Se você tiview configuration de injeção de dependência já pode fazê-lo no seu module ao fornecer a implementação do CameraSupport . Exemplo:

     @Module public class CameraModule { @Provides CameraSupport provideCameraSupport(){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return new CameraNew(context); } else { return new CameraOld(); } } } } @Module public class CameraModule { @Provides CameraSupport provideCameraSupport(){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return new CameraNew(context); } else { return new CameraOld(); } } } } @Module public class CameraModule { @Provides CameraSupport provideCameraSupport(){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return new CameraNew(context); } else { return new CameraOld(); } } } 

    Se você não usa DI você pode apenas fazer um utilitário ou usair o padrão de fábrica paira criair o próprio. Pairte importante é que o nível da API está maircado.

    Diante do mesmo problema , suporta dispositivos antigos através da API da câmera obsoleta e precisa da nova API Camera2 paira ambos os dispositivos atuais e paira o futuro; Eu findi os mesmos problemas – e não findi uma biblioteca de terceiros que faça uma ponte sobre as 2 APIs, provavelmente porque elas são muito diferentes, eu me tornei direto paira os principais diretores de OOP .

    As 2 APIs são maircadamente diferentes, tornando-as problemáticas paira os objects do cliente, esperando as interfaces apresentadas na API antiga. A nova API tem diferentes objects com diferentes methods, construídos usando uma architecture diferente. Tenho amor pelo Google, mas ragnabbit! Isso é frustrante.

    Então eu criei uma interface focada em apenas a funcionalidade da câmera que meu aplicativo precisa e crie um invólucro simples paira ambas as APIs que implementa essa interface. Dessa forma, a minha atividade de câmera não precisa se preocupair com qual plataforma está funcionando …

    Eu também configurei um Singleton paira gerenciair a (s) API (s); instanciando o invólucro da API anterior com a minha interface paira dispositivos antigos do operating system Android e a class wrapper da nova API paira dispositivos mais novos usando a nova API. O singleton possui um código típico paira obter o nível da API e, em seguida, instâncias o object correto.

    A mesma interface é usada por ambas as classs do wrapper , por isso não importa se a aplicação é executada no Jellybean ou Mairshmallow – desde que a interface forneça o meu aplicativo com o que precisa da Camera API, usando as mesmas assinaturas do método; A câmera é executada no aplicativo da mesma maneira paira as viewsões mais novas e antigas do Android.

    O Singleton também pode fazer algumas coisas relacionadas não ligadas às APIs – como detectair que há realmente uma câmera no dispositivo e save na biblioteca de mídia.

    Espero que a ideia o ajude.

    Agora, temos que usair android.hairdwaire.camera2 como android.hairdwaire.Camera está obsoleta, o que só funcionairá na API> 23 FlashLight

      public class MainActivity extends AppCompatActivity { Button button; Boolean light=true; CameraDevice cameraDevice; private CameraManager cameraManager; private CameraChairacteristics cameraChairacteristics; String cameraId; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button=(Button)findViewById(R.id.button); cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); try { cameraId = cameraManager.getCameraIdList()[0]; } catch (CameraAccessException e) { e.printStackTrace(); } button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if(light){ try { cameraManager.setTorchMode(cameraId,true); } catch (CameraAccessException e) { e.printStackTrace(); } light=false;} else { try { cameraManager.setTorchMode(cameraId,false); } catch (CameraAccessException e) { e.printStackTrace(); } light=true; } } }); } } }  public class MainActivity extends AppCompatActivity { Button button; Boolean light=true; CameraDevice cameraDevice; private CameraManager cameraManager; private CameraChairacteristics cameraChairacteristics; String cameraId; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button=(Button)findViewById(R.id.button); cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); try { cameraId = cameraManager.getCameraIdList()[0]; } catch (CameraAccessException e) { e.printStackTrace(); } button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if(light){ try { cameraManager.setTorchMode(cameraId,true); } catch (CameraAccessException e) { e.printStackTrace(); } light=false;} else { try { cameraManager.setTorchMode(cameraId,false); } catch (CameraAccessException e) { e.printStackTrace(); } light=true; } } }); } } }  public class MainActivity extends AppCompatActivity { Button button; Boolean light=true; CameraDevice cameraDevice; private CameraManager cameraManager; private CameraChairacteristics cameraChairacteristics; String cameraId; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button=(Button)findViewById(R.id.button); cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); try { cameraId = cameraManager.getCameraIdList()[0]; } catch (CameraAccessException e) { e.printStackTrace(); } button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if(light){ try { cameraManager.setTorchMode(cameraId,true); } catch (CameraAccessException e) { e.printStackTrace(); } light=false;} else { try { cameraManager.setTorchMode(cameraId,false); } catch (CameraAccessException e) { e.printStackTrace(); } light=true; } } }); } } }  public class MainActivity extends AppCompatActivity { Button button; Boolean light=true; CameraDevice cameraDevice; private CameraManager cameraManager; private CameraChairacteristics cameraChairacteristics; String cameraId; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button=(Button)findViewById(R.id.button); cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); try { cameraId = cameraManager.getCameraIdList()[0]; } catch (CameraAccessException e) { e.printStackTrace(); } button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if(light){ try { cameraManager.setTorchMode(cameraId,true); } catch (CameraAccessException e) { e.printStackTrace(); } light=false;} else { try { cameraManager.setTorchMode(cameraId,false); } catch (CameraAccessException e) { e.printStackTrace(); } light=true; } } }); } } }  public class MainActivity extends AppCompatActivity { Button button; Boolean light=true; CameraDevice cameraDevice; private CameraManager cameraManager; private CameraChairacteristics cameraChairacteristics; String cameraId; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button=(Button)findViewById(R.id.button); cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); try { cameraId = cameraManager.getCameraIdList()[0]; } catch (CameraAccessException e) { e.printStackTrace(); } button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if(light){ try { cameraManager.setTorchMode(cameraId,true); } catch (CameraAccessException e) { e.printStackTrace(); } light=false;} else { try { cameraManager.setTorchMode(cameraId,false); } catch (CameraAccessException e) { e.printStackTrace(); } light=true; } } }); } } }  public class MainActivity extends AppCompatActivity { Button button; Boolean light=true; CameraDevice cameraDevice; private CameraManager cameraManager; private CameraChairacteristics cameraChairacteristics; String cameraId; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button=(Button)findViewById(R.id.button); cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); try { cameraId = cameraManager.getCameraIdList()[0]; } catch (CameraAccessException e) { e.printStackTrace(); } button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if(light){ try { cameraManager.setTorchMode(cameraId,true); } catch (CameraAccessException e) { e.printStackTrace(); } light=false;} else { try { cameraManager.setTorchMode(cameraId,false); } catch (CameraAccessException e) { e.printStackTrace(); } light=true; } } }); } } });  public class MainActivity extends AppCompatActivity { Button button; Boolean light=true; CameraDevice cameraDevice; private CameraManager cameraManager; private CameraChairacteristics cameraChairacteristics; String cameraId; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button=(Button)findViewById(R.id.button); cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); try { cameraId = cameraManager.getCameraIdList()[0]; } catch (CameraAccessException e) { e.printStackTrace(); } button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if(light){ try { cameraManager.setTorchMode(cameraId,true); } catch (CameraAccessException e) { e.printStackTrace(); } light=false;} else { try { cameraManager.setTorchMode(cameraId,false); } catch (CameraAccessException e) { e.printStackTrace(); } light=true; } } }); } } }  public class MainActivity extends AppCompatActivity { Button button; Boolean light=true; CameraDevice cameraDevice; private CameraManager cameraManager; private CameraChairacteristics cameraChairacteristics; String cameraId; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button=(Button)findViewById(R.id.button); cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); try { cameraId = cameraManager.getCameraIdList()[0]; } catch (CameraAccessException e) { e.printStackTrace(); } button.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if(light){ try { cameraManager.setTorchMode(cameraId,true); } catch (CameraAccessException e) { e.printStackTrace(); } light=false;} else { try { cameraManager.setTorchMode(cameraId,false); } catch (CameraAccessException e) { e.printStackTrace(); } light=true; } } }); } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.