App Inventor Extensions


Screenshot Service Extension

See the App Inventor Extensions document about how to use an App Inventor Extension.

For questions about this extension or bug reports please start a new thread in the App Inventor community. Thank you.

For feature requests please contact me by email. To be a sponsor of a new method already is possible starting from only 10 USD! With your contribution you will help the complete App Inventor community. Thank you.

Jan 7th, 2021: Version 1: Initial version

Jan 20h, 2021: Version 2: delay added to give the user time to close the notification

Description

Screenshot Service Extension to capture a screenshot while the app is not running.
Minimum API level is 21 (Android 5).
Required permissions: android.permission.FOREGROUND_SERVICE

What does the user see?

After starting the service the capturing app will display the following "ugly" dialog to the user

Android 5 - Android 9

Starting from Android 10

The user must tap "Start Now" and a permanent notification will be displayed in the status bar for the user to start capturing a screenshot or shutdown the service.

Note: This extension does not work in Kodular, because Kodular still does not support AndroidX libraries!

Note: Do not use the close application block together with this extension. The code behind the close application block terminates the app in an ungraceful way and unfortunately also kills the running screenshot capture process. Please use the MoveTaskToBack method instead .

How does it work?

  1. Start your app, start the service, agree to the "ugly" dialog message and move your app to the back.
  2. Now start the app you like to capture a screenshot.
  3. From the Screenshot Service notification start the capturing and later shutdown the service.
  4. The captured screenshot will be stored in the ASD (Application Specific Directory) in png format.

Properties


Return Delay for screenshot.


Determines the delay in milliseconds to give the user time to close the notification. Default value is 500.


Return Filename for screenshot.


Filename for screenshot (png format). The file will be stored in the ASD - Application Specfic Directory. Default filename is TaifunScreenshot.png.


Return Sound (true or false).


Whether Sound should be on (true) or off (false). Default value is true. If set to true, a short beep sound will be played before and after capturing.


Return SmallIcon.


Set SmallIcon for notification. Recommended size is 96x96.


Return Title.


Set Title to be displayed in the notification. Default value is "Screenshot Service".


Return Text.


Set Text to be displayed in the notification. Default value is "Screenshot Service is running...".


Return Record Button text.


Set Text to be displayed in the record button of the notifier. Default value is 'Capture'.


Return Shutdown Button text.


Text to be displayed in the shutdown button of the notifier. Default value is 'Shutdown'.

Methods


Start Service
Note: You will have to build the app to be able to test.


Shutdown Service
Note: You will have to build the app to be able to test.


Move task (i.e. the app) to the background.


Get complete path to the last taken screenshot in the ASD - Application Specfic Directory.

Events


Event indicating if media projection permission has been obtained or not.

Example App Screenshot Service Test

 

Screenshots



There is not much to see in the example app itself, because the main functionality will be triggered in the notification. Depending on the Android version, the notification looks a little bit different...

Android 5


Android 6


Android 7


Android 8


Android 9


Android 10


Test

Tested successfully on Samsung Galaxy A51 running Android 10.

Questions and Answers

currently none

Terms and Conditions

Download


Developing and maintaining snippets, tutorials and extensions for App Inventor takes a lot of time.
I hope it saved some of your time. If yes, then you might consider to donate a small amount!

Donation amount:

or donate some mBTC to Bitcoin Address:
1Jd8kXLHu2Vkuhi15TWHiQm4uE9AGPYxi8
Bitcoin

Thank you! Taifun
 

Download TaifunScreenshotService extension (aix file)
Download ScreenshotService example project (aia file)

Back to top of page ...

Creative Commons License
This work by Pura Vida Apps is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
with attribution (name=Pura Vida Apps and link to the source site) required.


Home | Snippets | Tutorials | Extensions | Links | Search | Privacy Policy | Contact