Giter Site home page Giter Site logo

easyflashlight's People

Contributors

pddstudio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

easyflashlight's Issues

java.lang.NoClassDefFoundError: com.pddstudio.easyflashlight.EasyFlashlight$DeviceStateCallback

error

package com.example.android.flash;

import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.graphics.Camera;
import android.hardware.camera2.*;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.hardware.Camera.Parameters;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.pddstudio.easyflashlight.EasyFlashlight;

import java.security.Policy;
import java.security.PrivateKey;

public class MainActivity extends AppCompatActivity {
   
    ImageView torchButtonImageView;
    private static Camera camera = null;
    private boolean isFlashOn;
    private boolean hasFlash;
    Parameters params;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        EasyFlashlight.init(this);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                
                finish();
                System.exit(0);
            }
        });

        torchButtonImageView = (ImageView) findViewById(R.id.torch_button);
        torchButtonImageView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (isFlashOn) {
                    // turn off flash
                    turnOffFlash();
                } else {
                    // turn on flash
                    turnOnFlash();
                }
            }
        });

      
    // First check if device is supporting flashlight or not

        hasFlash = EasyFlashlight.getInstance().canAccessFlashlight();

        if (!hasFlash) {
            // device doesn't support flash
            // Show alert message and close the application
            AlertDialog alert = new AlertDialog.Builder(MainActivity.this)
                    .create();
            alert.setTitle("Error");
            alert.setMessage("Sorry, your device doesn't support flash light!");
            alert.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    // closing the application
                    finish();
                }
            });
            alert.show();
            return;
        }

    }


    
 //Turning On flash
 
    private void turnOnFlash() {

        EasyFlashlight.getInstance().turnOn();
            isFlashOn = true;

            // changing button/switch image
            toggleButtonImage();


    }
   
 //Turning Off flash
 
    private void turnOffFlash() {

        EasyFlashlight.getInstance().turnOff();
            isFlashOn = false;

            // changing button/switch image
            toggleButtonImage();

    }
    
 //Toggle switch button images
 //changing image states to on / off
 
    private void toggleButtonImage(){
        if(isFlashOn){
            torchButtonImageView.setImageResource(R.drawable.on);
        }else{
            torchButtonImageView.setImageResource(R.drawable.off);
        }
    }

// Switch click event to toggle flash on/off
 

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }



    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
        //For Android M Support, call this in your onRequestPermissionsResult method
        EasyFlashlight.getInstance().onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

}

Getting crash with Android 5 devices

The crash happens in line 199 in EasyFlashlight.java

The crash happens on Android 4/5-devices but not on an Android 8 device.
(I suppose the camera2-API is only present beginning with API-Level 21. Why does EasyFlashlight specifiy minSdkVersion 16?) Thanks for help.

Android Build: LRX22C.I9505XXUHOJ2
Manufacturer: samsung
Model: GT-I9505
Thread: main-1
CrashReporter Key: 94F0F560-EBD3-3959-D061-D97E30B6241138E1A418
Start Date: Wed Oct 04 10:49:49 GMT+02:00 2017
Date: Wed Oct 04 10:49:59 GMT+02:00 2017

java.lang.IllegalArgumentException: Bad argument passed to camera service
	at android.hardware.camera2.utils.CameraBinderDecorator.throwOnError(CameraBinderDecorator.java:114)
	at android.hardware.camera2.utils.CameraBinderDecorator$CameraBinderDecoratorListener.onAfterInvocation(CameraBinderDecorator.java:73)
	at android.hardware.camera2.utils.Decorator.invoke(Decorator.java:81)
	at java.lang.reflect.Proxy.invoke(Proxy.java:397)
	at $Proxy14.createDefaultRequest(Unknown Source)
	at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureRequest(CameraDeviceImpl.java:481)
	at com.pddstudio.easyflashlight.EasyFlashlight$DeviceStateCallback.onOpened(EasyFlashlight.java:199)
	at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:118)
	at android.os.Handler.handleCallback(Handler.java:739)
	at android.os.Handler.dispatchMessage(Handler.java:95)
	at android.os.Looper.loop(Looper.java:145)
	at android.app.ActivityThread.main(ActivityThread.java:5951)
	at java.lang.reflect.Method.invoke(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:372)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)```

Heavy battery drilling

Hi, I don't know why, but your library drilling the battery of every device super fast even without using the flashlight! The battery drilling process start after EasyFlashlight.init(this); I have a lock screen app with a button to turn ON/OFF the flashlight. Last night I put my Galaxy S6 Edge on airplane mode with 96% full battery. After 4 hours without any use and display turned OFF, the battery of my device was drilled to 0%. On Nexus 5 for example the process is twice faster. After removing the library - no battery lost.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.