Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
424 views
in Technique[技术] by (71.8m points)

java - 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...