• Stars
    star
    234
  • Rank 171,630 (Top 4 %)
  • Language
    Java
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 7 years ago

Reviews

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

Repository Details

Android library helps take screenshots for publishing on Google Play Store.

API JCenter Android Arsenal Android Weekly

ScreenshotsNanny

Introduction

Until the time of writing, the Android toolchain doesn't have anything to help take screenshots automatically for publishing on Google Play Store.

The other fact is that most of the modern apps consume internet resources, or have UGC (user-generated content). And for the screenshots showing on Google Play, no one would like to see any arbitrary content which may be ugly or even inappropriate.

Be professional! Be beautiful! You can achieve it easily by using ScreenshotsNanny.

Comparison

Below are two different screenshots for the same activity. The left one is using real arbitrary content, while the right one is using prepared mock response.

Comparison

Setup & Sample code

There are two approaches to utilizing this library.

  • Setup an automated UI test (e.g. Espresso).
  • Create another product flavor in your project to do the screenshot job.

I'll explain the product flavor approach in detail. You can also check out the demo module along with this project.

1 - Add a product flavor (let's name it "screenshots") to your target module's build.gradle:

productFlavors {
    prod {
        applicationId "PRODUCT_DEFAULT_APP_ID"
    }
    screenshots {
        applicationId "PACKAGE_NAME.screenshots"
    }
}

2 - Create a blank dummy activity in the screenshots flavor: MODULE/src/screenshots/java/PACKAGE_NAME/ScreenshotsPrimeActivity.java

You can leave the layout as it is (an empty view group), because we don't really need it.

3 - Set the created activity as the launcher activity in that product flavor:

MODULE/src/screenshots/AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application>
        <activity android:name="PACKAGE_NAME.ScreenshotsPrimeActivity"
            android:label="@string/title_activity_screenshots_prime">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
</manifest>

4 - Add the core screenshot code to the new launcher activity ScreenshotsPrimeActivity.java.

There are two major methods: startActivityAndTakeScreenshot & startActivityContainsMapAndTakeScreenshot. Without passing screenshotDelay, the former one uses default value 3 seconds, and the latter one takes screenshot immediately when map view is ready. You could give your own screenshotDelay to both of the methods.

public class ScreenshotsPrimeActivity extends AppCompatActivity {

    private MockServerWrapper mServer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_screenshots_prime);

        // Set up the screenshot fixture

        // Set language (resources configuration) other than the default one if it's necessary
        // LanguageSwitcher.change(this, "de");

        // Set up the mock server
        mServer = new MockServerWrapper();
        // Read mock response(s) from resource directory
        String response = ResourceReader.readFromRawResource(ScreenshotsPrimeActivity.this, R.raw.github_user);
        ParameterizedCallback changeUrlCallback = new ParameterizedCallback() {
            @Override
            public void execute(String value) {
                // The MockServer runs on arbitrary port each time
                // We have to change production's base URL to the MockServer URL via reflection
                PowerChanger.changeFinalString(GithubService.class, "API_URL", value);
            }
        };
        // Start mock server with canned response(s), it accepts response(s) as varargs
        mServer.start(changeUrlCallback, response);
    }

    @Override
    protected void onResume() {
        super.onResume();

        // Start desired activities one by one, and take screenshot accordingly

        startActivityAndTakeScreenshot(MainActivity.class, new Callback() {
            @Override
            public void execute() {
                // Start a normal activity
                startActivity(new Intent(ScreenshotsPrimeActivity.this, MainActivity.class));
            }
        });

        startActivityAndTakeScreenshot(SecondActivity.class, new Callback() {
            @Override
            public void execute() {
                // Start an activity by an intent which contains something
                startActivity(SecondActivity.createIntent(ScreenshotsPrimeActivity.this, "London bridge is falling down"));
            }
        });

        startActivityAndTakeScreenshot(NetworkActivity.class, new Callback() {
            @Override
            public void execute() {
                // This activity will consume mock response and present it
                startActivity(new Intent(ScreenshotsPrimeActivity.this, NetworkActivity.class));
            }
        });

        startActivityAndTakeScreenshot(AccountActivity.class, new Callback() {
            @Override
            public void execute() {
                // Prepare persistent data before starting the activity
                AccountManager.create(getApplicationContext(), "Bruce Lee");
                AccountManager.update(getApplicationContext(), 1048576);
                startActivity(new Intent(ScreenshotsPrimeActivity.this, AccountActivity.class));
            }
        });

        startActivityContainsMapAndTakeScreenshot(MapsActivity.class, new Callback() {
            @Override
            public void execute() {
                // Take screenshot for an activity which contains Map, need to pass map view id
                startActivity(new Intent(ScreenshotsPrimeActivity.this, MapsActivity.class));
            }
        }, R.id.map);

        if (!ActivityCounter.isAnyActivityRunning) {
            Log.i(Constants.LOG_TAG, "βš™ Done.");
            // Stop mock server when all screenshot jobs are done
            mServer.stop();
            finish();
        }
    }
}

5 - Select screenshotsDebug as build variant, run it. Then all screenshots will be placed under DEVICE_STORAGE/Screenshots/APP_NAME/. Each screenshot file is named as corresponding activity name (format is PNG).

Screenshots

  • The Android Status Bar won't be captured as part of the screenshot, so you don't have to worry about the messy icons there.
  • Forget about the annoying on-screen keyboard, this library will hide it for you.
  • MapView (no matter if it fulfills the window or not) will also be taken into the screenshot.
  • For any activity consumes network resources, you can replace the content by canned mock responses. (This library is using MockWebServer from Square, Inc.)
  • Some activities may read values from persistent data (e.g. SharedPreferences), you can also prepare the values before activity starts.

(sorry, these demo activities layouts were made with poor design, look ugly)

Logs

Filter: tag = SSN

Logs

Import as dependency

Gradle: (available in Bintray's JCenter)

dependencies {
    compile 'com.basgeekball:screenshots-nanny:1.2'
}

Publish

gradle generateRelease

License

Copyright (c) 2015 Jing Li. See the LICENSE file for license rights and limitations (MIT).

Last but not least

This is made in Berlin with love and passion Κ•Β΄β€’α΄₯β€’`Κ”

More Repositories

1

AndroidSDK

🐳 Full-fledged Android SDK Docker Image
Dockerfile
1,252
star
2

AwesomeValidation

Android validation library which helps developer boil down the tedious work to three easy steps.
Java
1,152
star
3

Charles-Proxy-Mobile-Guide

The mobile hackers' guide to Charles Proxy πŸ‘
140
star
4

awesome-asus-tinker-board

A curated list of ASUS Tinker Board resources
63
star
5

AirPdfPrinter

Virtual PDF AirPrint printer
Dockerfile
57
star
6

Captain-ADB

Providing simple web API and view for Android Debug Bridge (adb). Free your imagination, use it as the way you want.
Ruby
51
star
7

namedict

Generate Chinese names for the newborn baby which are also applicable for multilingual pronunciation (English, and maybe Deutsch).
Ruby
41
star
8

SonarOnDocker

🐳 πŸ“‘ Docker way of running SonarQube + any DB
Java
25
star
9

AgileNotifier

Agile Notifier - an easy way of monitoring Agile SW Engineering, including CI (Continuous Integration), SCM (Source Control Management), and ITS (Issue Tracking System).
Ruby
16
star
10

jooi

Convert the results of Infer (static analyzer by Facebook) to JUnit format results.
Ruby
15
star
11

MacManual

Installation and Setup Guide
14
star
12

PermissionMatters

Check your Android application's permission changes
Go
14
star
13

MobileDevicePool

Web UI to manage your mobile devices kingdom.
Ruby
14
star
14

NoNewPermissionForAndroid

Ruby
10
star
15

TechNewsletter

The engineering way of composing a responsive design newsletter email in markup language
Ruby
8
star
16

dotfiles

Shell
4
star
17

Lifecycle

A curated list of lifecycle explanation in illustration
4
star
18

reMarkable

My reMarkable resources
Shell
4
star
19

AppReputation

Ruby gem for retrieving application's ratings and reviews
Ruby
4
star
20

N0L1mIT

No Limit - η„‘η–†
Shell
4
star
21

JunitReportGenerator

Easy and flexible solution to generating JUnit test result report from any format of data.
Ruby
3
star
22

cryonics

A Chrome extension which helps user save all opened tabs and resuscitate them all at once later.
JavaScript
3
star
23

ACES

ACES - A Chrome Extension Scaffold
HTML
2
star
24

GeekGadgets

2
star
25

CozmoSDK

Anki’s CozmoSDK
Nix
2
star
26

Kotlinker

Kotlin Docker Image
2
star
27

Smarping

Smart shopping list benefits from machine learning (not yet)
Java
2
star
28

Doraemon

A bot
JavaScript
2
star
29

AndroidSDKPackagesDownloader

Download missing Android SDK packages automatically via Gradle (from dummy project dependencies)
Java
2
star
30

RegionChanger

Change region (language, IP address) on the go - debug companion
Java
2
star
31

CurriculumVitae

RΓ©sumΓ© template in LaTeX
TeX
2
star
32

GoJourney

My journey of learning Go
1
star
33

thyrlian.github.io

Website for Basgeekball
CSS
1
star
34

PupilProgramming

Teach πŸ‘¦ how to πŸ‘¨β€πŸ’»
Ruby
1
star
35

MCGW

Most Common German Words - a web crawler extracts vocabularies from canonical German news websites
Ruby
1
star
36

EngineeringExcellence

Engineering Excellence Methodology
1
star
37

BuildCompanion

Your companion for build - monitor, notify, analyze
1
star
38

ComicCollection

Load your comic collection to a server
1
star
39

JIRA-Steward

Kotlin
1
star
40

gradleman

A man who helps you with gradle stuff.
Ruby
1
star
41

VideoHub

Play your videos everywhere (on mobile, Chromecast or whatever)
Ruby
1
star
42

LAB

My personal laboratory for trying out and learning about something new to me πŸ‘¨β€πŸ”¬πŸ”¬
Kotlin
1
star
43

OpenStackSwissKnife

A Docker image contains Swiss knife tool set for managing OpenStack
Shell
1
star
44

mind_the_changes

Mind the code changes since last release
Ruby
1
star
45

PersonalizedBulletinBoard

1
star