The motivation behind this repository is to learn how to create a simple Android application, deploy the obtained .apk on a real device and try to decompile the application in order to see how the packaged source code looks like. Although educational, the application is still useful when light is needed :)
We accomplish this by having the android.permission.CAMERA
permission, along with android.hardware.camera
and android.hardware.camera.autofocus
features added in the AndroidManifest.xml
Next, we continue by building a simple UI in activity_main.xml
that contains at least a Button having the toggleButton
id.
The main code can be found in the setOnClickListener
which:
- Gets the camera manager:
final CameraManager cameraManager = (CameraManager) getSystemService(CAMERA_SERVICE);
- If not provided by the user, requests permission for the camera:
ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.CAMERA}, 2);
- Finally, turn on the back facing camera led:
cameraManager.setTorchMode(cameraId, toggleBtn.isChecked());
Below is a fully functional demo of the apk_release/flashligh-app-debug.apk
The following command allows us to see how the code is packaged:
`chmod +x apk_decompiler/dex2jar/*.sh && java -jar apk_decompiler/jd-gui-1.6.6.jar flashligh-app-debug-dex2jar.jar
We must expand the com.example.flashlight package in order to see the code from MainActivity: