Android Hidden Camera


Source link: https://github.com/kevalpatel2106/android-hidden-camera

Android Hidden Camera

What is this library for?

This library allows application to take the picture using the device camera without showing the preview of it. Any application can capture the image from front or rear camera from the background service and this library will handle all the complexity on behalf of the application. You can capture images from activity, fragment and even from the background service using this library.

Gradle Dependency:

dependencies {

  compile 'com.kevalpatel2106:hiddencamera:1.3.3' 
}
 

How to integrate?

Step-1: Inherit the builtin class.

Component Class to inherit Sample
Activity com.androidhiddencamera.HiddenCameraActivity public class DemoCamActivity extends HiddenCameraActivity {
Fragment com.androidhiddencamera.HiddenCameraFragment public class DemoCamFragment extends HiddenCameraFragment {
Service com.androidhiddencamera.HiddenCameraService public class DemoCamService extends HiddenCameraService {

Step-2: Create the camera configuration. In this developer can define which camera they want to use, output image format, capture image resolution etc parameters.

//Setting camera configuration mCameraConfig = new CameraConfig()
  .getBuilder(getActivity())
  .setCameraFacing(CameraFacing.FRONT_FACING_CAMERA)
  .setCameraResolution(CameraResolution.MEDIUM_RESOLUTION)
  .setImageFormat(CameraImageFormat.FORMAT_JPEG)
  .setImageRotation(CameraRotation.ROTATION_270)
  .build();
 

Step-3: Start the camera in onCreate() by calling startCamera(CameraConfig). Before starting the camera, ask user for the camera runtime permission.

//Check for the camera permission for the runtime if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {

//Start camera preview
  startCamera(mCameraConfig);
 
}
 else {

  ActivityCompat.requestPermissions(getActivity(), new String[]{
Manifest.permission.CAMERA
}
, 101);
 
}
 
  • If you are capturing the image from the service, you have to check if the application has the draw ver other application permission or not? If the permission is not available, application can ask user to grat the permission using HiddenCameraUtils.openDrawOverPermissionSetting().
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {

  if (HiddenCameraUtils.canOverDrawOtherApps(this)) {

...

...
  
}
 else {

//Open settings to grant permission for "Draw other apps".

HiddenCameraUtils.openDrawOverPermissionSetting(this);

  
}
 
}
 else {

  //TODO Ask your parent activity for providing runtime permission 
}
 

Step-4: Take image in background whenever you want by calling takePicture(). You will receive captured image file in onImageCapture() callback.

Step -5: Handle errors by overriding onError() callback. In this callback you will receive an error code for each error occurred. You can take specific actions based on the error code.

@Override public void onCameraError(@CameraError.CameraErrorCodes int errorCode) {

  switch (errorCode) {

case CameraError.ERROR_CAMERA_OPEN_FAILED:

 //Camera open failed. Probably because another application

 //is using the camera

 break;

case CameraError.ERROR_IMAGE_WRITE_FAILED:

 //Image write failed. Please check if you have provided WRITE_EXTERNAL_STORAGE permission

 break;

case CameraError.ERROR_CAMERA_PERMISSION_NOT_AVAILABLE:

 //camera permission is not available

 //Ask for the camra permission before initializing it.

 break;

case CameraError.ERROR_DOES_NOT_HAVE_OVERDRAW_PERMISSION:

 //Display information dialog to the user with steps to grant "Draw over other app"

 //permission for the app.

 HiddenCameraUtils.openDrawOverPermissionSetting(this);

 break;

case CameraError.ERROR_DOES_NOT_HAVE_FRONT_CAMERA:

 Toast.makeText(this, "Your device does not have front camera.", Toast.LENGTH_LONG).show();

 break;
  
}
 
}
 

That's it.

Demo

  • You can download the sample apk from here.

Contribute:

Simple 3 step to contribute into this repo:

  1. Fork the project.
  2. Make required changes and commit.
  3. Generate pull request. Mention all the required description regarding changes you made.

Questions

Hit me on twitter

License

Copyright 2017 Keval Patel

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Resources

Install Referrer is an Open Source application that allows you to test the referrer attribute on the Google Play Store

Android reactive bluetooth library.

RxJava SharedPreferences for Android, lightweight and extendable.

Linear layout, that wrap its content to the next line if there is no space in the current line.

OpenALPR is an open source Automatic License Plate Recognition library.

A LayoutManager that must be used with RecyclerView. When list is scrolled views are moved by circular trajectory.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes