• Stars
    star
    396
  • Rank 108,801 (Top 3 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This library is to take picture using camera without camera preview.

Android Hidden Camera

Build Status Download API

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.
  • sample

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 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.

More Repositories

1

android-ruler-picker

Android custom view that uses ruler for picking the number from given range.
Java
381
star
2

EmoticonGIFKeyboard

An advance Emoticons & GIF keyboard.
Java
273
star
3

PasscodeView

PasscodeView is an Android Library to easily and securely authenticate user with PIN code or using the fingerprint scanner.
Java
272
star
4

android-samples

Repository that contains android tutorial projects and sample applications
Java
229
star
5

Prevent-Screen-Off

This is the library that keeps the screen on until user is looking at the screen.
Java
176
star
6

FingerprintDialogCompat

FingerprintDialog from Android 28 (P) back ported to Android 23 (M).
Java
104
star
7

android-ringtone-picker

Simple Ringtone Picker dialog which allows you to pick different sounds from ringtone, alarm tone, notification tone and music from external storage.
Java
74
star
8

green-build

An android app for managing your CI builds.
Kotlin
73
star
9

UserAwareVideoView

A customized video view that will automatically pause video is user is not looking at device screen!!!!!
Java
51
star
10

Open-Weather-API-Wrapper

An Android wrapper for the APIs of https://openweathermap.org
Java
22
star
11

remote-storage-android-things

Create an FTP server using on raspberry pi and build your own wireless storage & backup solution for home.
Java
20
star
12

year-in-progress

Deadline tracker
Kotlin
17
star
13

PastryShop

Take home task for the cookpad interview (Sr. Android Engineer) 2018
Kotlin
15
star
14

smart-lens

Get the information of object based on image recognition using TensorFlow.
Java
12
star
15

unity-lamborghini-car

See Lamborghini in the real world.
C#
12
star
16

unity-snake-game

This is smaple 2D unity snake game.
C#
12
star
17

collision-detector-android-things

Get the distance of the object using Android Things & ultrasonic ranging sensor HC-SR04.
Java
10
star
18

pocket-ci

Check your builds from your pocket
Kotlin
9
star
19

smartswitch

Control your home switches remotely from phone using Android Things.
Java
9
star
20

torrent-downloader-android-things

Java
7
star
21

github-issue-cloud-function

๐Ÿ”ฅ Firebase cloud function to post a GitHub issue whenever new crash๐Ÿž reported in firebase crashalytics.
JavaScript
7
star
22

rxbus

Implementation of event bus using Rx for Android.
Java
5
star
23

remote-bluetooth-speaker-android-things

Java
5
star
24

Currency-Converter-App

Currency converter android app
Kotlin
4
star
25

robo-car

Java
4
star
26

crypto-wallet

Demo application for displaying the Bitcoin transaction in Crypto Wallet.
Kotlin
3
star
27

gitlab-ci-android

GitLab CI Docker image to create android builds.
Shell
3
star
28

basic-android

A ready to start from scratch setup for android application project
Java
3
star
29

Github-User-Search

Java
3
star
30

vuforia-barcode-scanner

A barcode scanner for Vuforia based AR applications.
C#
2
star
31

google-home-andorid-things

Protocol Buffer
2
star
32

Stand-Up

Sitting is next cancer.
Kotlin
2
star
33

brew

Kotlin
2
star
34

kevalpatel2106.github.io

Source code for my personal website.
SCSS
2
star
35

rpi-setup

This script will set up your raspberry pi after first boot.
Shell
1
star
36

kevalpatel2106

1
star
37

ar-solar-system

Augmented reality specific model of the solar system using unity in ARCore.
C#
1
star
38

SpinWheelView

Java
1
star
39

home

Java
1
star