简体   繁体   中英

How to force app to create thumbnail (snapshot) for recent apps list?

Tester of my app has reported: "The thumbnail of the app in the Recent apps list is not tuned at all. At me it appears either like a homescreen wallpapers (tolikdru: probably, just transparent rect), or like green background of the app screen, but never as a real snapshot of the app." So the behaviour is something like described here .

My device is with Android 2.0 so I cannot check and debug the issue (thumbnails in Recent apps are since Android 3.0+). So further research was in a "blind mode".

I decided to manually force creation of app thumbnail using onCreateThumbnail() as proposed here . (To simplify the task for the beginning, I do not catch a real snapshot but take the splashscreen drawable.)

@Override
public boolean onCreateThumbnail(Bitmap outBitmap, Canvas thumbCanvas) {
    super.onCreateThumbnail(outBitmap, thumbCanvas);

    //splashscreen drawable to bitmap
    outBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.titel);

    //automatically scale to provided canvas 
    //(is the canvas provided as input ???)
    thumbCanvas.drawBitmap(outBitmap, 0, 0, new Paint());

    //is the outBitmap itself scaled to canvas or its copy???
    return true;
}

I am not sure if the code above is correct because I cannot test it (see below).

According to docs another possible solution may be just a dummy @Override onCreateThumbnail with only super.onCreateThumbnail() inside, since the docs say:

The default implementation returns fails and does not draw a thumbnail; this will result in the platform creating its own thumbnail if needed.

But the onCreateThumbnail method doesn't fire , at least on my Android 2. Actually the trick is designed to work on Android 3+. The same is reported here (year 2012) and also here (year 2009) . In both cases used Android version is not specified.

So will you please help with the questions:

1) Will the code above work on Android 3+ devices that using thumbnails in Recent apps list?

2) If nope, is there any other workaround to make the app to generate a correct thumbnail (or arbitrary drawable to my choice)?

Thanks in advance!

This is an issue with the OS . Unfortunately, it just doesn't seem to work. If you don't want people looking at your app from the recents for some reason, you can put

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE)

As the first line in your onCreate() method of the activity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM