• Stars
    star
    318
  • Rank 131,872 (Top 3 %)
  • Language
    Java
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

Take pictures ๐Ÿ“ท secretly (without preview or launching device's camera app) using Android CAMERA2 API

Build Status

๐Ÿ“ธ Android Camera2 Secret Picture Taker (AC2SPT)

Take pictures secretly (without preview or launching device's camera app) from all available cameras using Android CAMERA2 API. The Camera2 API replaces the deprecated Camera class.


How can I support this project?

  • If you have enjoyed the project and it helped you creating a project, building an app, starting a business. You could encourage and support me on patreon https://www.patreon.com/hzitoun ๐Ÿค— !
  • Star this GitHub repo โญ
  • Create pull requests, submit bugs, suggest new features or documentation updates ๐Ÿ”ง

Usage

  1. Implement the interface PictureCapturingListener (your capture listener) and override the following methods:
    • void onDoneCapturingAllPhotos(TreeMap<String, byte[]> picturesTaken) which is called when we've done taking pictures from ALL available cameras OR when NO camera was detected on the device;
    • void onCaptureDone(String pictureUrl, byte[] pictureData) to get a couple (picture Url, picture Data). Use this method if you don't want to wait for ALL pictures to be ready;
  2. Create a new instance of APictureCapturingService using PictureCapturingServiceImpl#getInstance() method;
  3. Start capture by calling the method APictureCapturingService#startCapturing(PictureCapturingListener listener) and pass the listener you've just implemented (step 1)

Sample

Here, I've chosen to just display the two pictures taken within a vertical linear layout. Here is a code snippet of how to use the service:

public class MainActivity extends AppCompatActivity implements PictureCapturingListener, ActivityCompat.OnRequestPermissionsResultCallback {
     private APictureCapturingService pictureService;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //check for camera and external storage permissions
        checkPermissions();
        final Button btn = (Button) findViewById(R.id.startCaptureBtn);
        pictureService = PictureCapturingServiceImpl.getInstance(this);
        //start capturing when clicking on the button
        btn.setOnClickListener(v ->
                pictureService.startCapturing(this)
        );
    }

    @Override
    public void onDoneCapturingAllPhotos(TreeMap<String, byte[]> picturesTaken) {
        if (picturesTaken != null && !picturesTaken.isEmpty()) {
            picturesTaken.forEach((pictureUrl, pictureData) -> {
               //convert the byte array 'pictureData' to a bitmap (no need to read the file from the external storage) but in case you
               //You can also use 'pictureUrl' which stores the picture's location on the device
                final Bitmap bitmap = BitmapFactory.decodeByteArray(pictureData, 0, pictureData.length);
            });
            showToast("Done capturing all photos!");
            return;
        }
        showToast("No camera detected!");
    }

    @Override
    public void onCaptureDone(String pictureUrl, byte[] pictureData) {
        if (pictureData != null && pictureUrl != null) {
            runOnUiThread(() -> {
                //convert byte array 'pictureData' to a bitmap (no need to read the file from the external storage)
                final Bitmap bitmap = BitmapFactory.decodeByteArray(pictureData, 0, pictureData.length);
                //scale image to avoid POTENTIAL "Bitmap too large to be uploaded into a texture" when displaying into an ImageView
                final int nh = (int) (bitmap.getHeight() * (512.0 / bitmap.getWidth()));
                final Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 512, nh, true);
               //do whatever you want with the bitmap or the scaled one...
            });
            showToast("Picture saved to " + pictureUrl);
        }
    }
    
    private void showToast(final String text) {
        runOnUiThread(() ->
                Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show()
        );
    }

}

Thanks to maaudrana for the logo :)

Contributors

Hamed ZITOUN [email protected]

Help

If you run into issues, please don't hesitate to find help on the GitHub project.

License

The android-camera2-secret-picture-taker is covered by the MIT License.

The MIT License (MIT)

Copyright (c) 2022 Hamed ZITOUN and contributors to the android-camera2-secret-picture-taker project.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

machine_learning_from_scratch_matlab_python

Vectorized Machine Learning in Python ๐Ÿ From Scratch
Jupyter Notebook
30
star
2

cognitiveclass-applied-data-science-with-python

All the work done by me as part of IBM's CongnitiveClass "Applied Data Science with Python ๐Ÿ" Learning Path.
Jupyter Notebook
10
star
3

datacamp-machine-learning-with-scikit-learn

All the work done by me as part of DataCamp's "Machine Learning with Python ๐Ÿ" Track.
Jupyter Notebook
8
star
4

data-scientist-udacity-nanodegree

All the work done by me as part of Udacity's Data Scientist Nanodegree
Roff
4
star
5

smallNodeWS

A small RESTFULL API using Nodejs, Expressjs, Mongoose and Gulp.
JavaScript
3
star
6

tensorflow-2-image-classification-rest-api

A REST API Serving a Tensorflow 2 keras deep learning model to classify image
Python
3
star
7

tensorFlow-2-Deep-Learning-Image-Classifier-REST-API-Docker-GPU

Source code for medium story ๐Ÿš€Create & Serve a TensorFlow 2 Deep Learning Image Classifier as a REST API and Dockerize it! (with GPUย support)
Jupyter Notebook
3
star
8

applying-machine-learning

Applying the Machine Learning Algorithms I've learned (https://github.com/hzitoun/coursera_machine_learning_course) to Real World DataSets In Python ๐Ÿ
Jupyter Notebook
2
star
9

simpop

Simple Popup (Html 5)
JavaScript
2
star
10

datacamp-deep-learning

DataCamp's Deep Learning in Python ๐Ÿ & Keras
Jupyter Notebook
2
star
11

elastichsearch_python

Going from 0 to 1 in Elasticsearch with ๐Ÿ
Jupyter Notebook
1
star
12

image-search-engine-app

Deep Learning with TensorFlow 2.0 for Image Search Engine
Jupyter Notebook
1
star
13

fireBaseChatSystem

A Real-time chat system using FireBase the NoSQL cloud database.
JavaScript
1
star
14

ang2advexp

angular2 advanced example (angular2, nodejs, gulp, typescript, typings, npm...)
TypeScript
1
star
15

xebia-technical-test

XTT - Xebia Technical Test
Java
1
star
16

spring-hibernate-criteria-builder-p6spy

Java
1
star