0

Currently I'm working on an app which is supposed to take screenshots from the device screen.

I read about Android Screenshot Library and it sounds very promising.

I want to start using it in my app. The problem is I'm having hard times embed it into my project.

I tried to import the project folder(asl-1.2) into my libs directory inside the app module.

I followed this post but it still doesn't help me.

The problem is the project is not linked with my app module and therefore I can't use the classes that reside in the library.

Here is a screenshot of the project hierarchy:

https://i.gyazo.com/f496e790d5ab06fc4c785df77e0984bd.png

As you can see, the ScreenshotService.java file is marked with the red icon with the letter 'J'

David Lasry
  • 829
  • 3
  • 12
  • 31

2 Answers2

0

What is the need of library for taking Screenshots ? Use the following function function to get Bitmap of any view .

public Bitmap getBitmapFromView(View view) {
    Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
         Canvas canvas = new Canvas(returnedBitmap);
    Drawable bgDrawable =view.getBackground();
    if (bgDrawable!=null)
        bgDrawable.draw(canvas);
    else
        canvas.drawColor(Color.WHITE);
    view.draw(canvas);
 return returnedBitmap;
}
Rishabh Maurya
  • 1,448
  • 3
  • 22
  • 40
  • 1
    At best, that takes "screenshots" of a `View` in the current activity. The aforementioned library -- to the extent it works -- was capable of taking screenshots of whatever was on the screen, including third-party activities. – CommonsWare May 29 '17 at 17:29
  • @CommonsWare Didn't know about that library ! – Rishabh Maurya May 29 '17 at 17:31
0

I read about Android Screenshot Library and it sounds very promising.

That code has not been updated in six years. AFAIK, it requires that users have USB cables and the Android SDK installed (since it relies upon developer tools).

On Android 5.0+, you can use the media projection APIs to take screenshots.

I tried to import the project folder(asl-1.2) into my libs directory inside the app module.

That is not going to work. libs/ is for bare JAR files, such as legacy Java code.

Either merge its contents directly into your app module, or set up a separate library module for that code. Most likely, that code will require substantial reorganization, to be buildable by Android Studio and the modern NDK.

Or, don't use that code, which IMHO is the best answer.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thank you for you answer :) I want my app to be able to capture the screen even if the app is not visible. How can I do that, considering what you said about this library – David Lasry May 29 '17 at 17:35
  • @DavidLasry: As I wrote, use the media projection APIs on Android 5.0+. See [this sample app](https://github.com/commonsguy/cw-omnibus/tree/master/MediaProjection/andshooter). There is no supported way to do this on older devices. – CommonsWare May 29 '17 at 17:38