Android:自定义最近使用的应用缩略图(默认情况下为屏幕截图) [英] Android: Customizing recent apps thumbnail (screenshot by default)

查看:407
本文介绍了Android:自定义最近使用的应用缩略图(默认情况下为屏幕截图)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的应用程序显示了一些敏感信息,当按下主屏幕按钮停止应用程序时,这些信息不能显示在最近的任务"屏幕上.

The app I'm working on shows some sensitive information that must not be shown on the "Recent Tasks" screen when stopping the app by pressing the home button.

我想模糊屏幕截图中的敏感数据,或者改为显示应用徽标.

I'd like to blur the sensitive data in the screenshot or show the app logo instead.

我知道以下方法,但它们不符合我的要求:

I am aware of the following approaches but they don't fit my requirements:

  • 在manifiedt中将actvitie的android:excludeFromRecents设置为true会阻止该应用程序在最近的任务中完全显示.这会破坏用户体验.
  • 使用FLAG_SECURE在最近任务"屏幕上显示空白卡. (​​如何当我的应用程序进入后台时,是否可以防止Android截屏?)我不喜欢黑屏.但是,如果没有解决方法,我将坚持使用此解决方案.
  • 覆盖onCreateThumbnail似乎是理想的解决方案,但不幸的是,由于操作系统当前未调用它,因此无法正常工作:(((
  • Setting the actvitie's android:excludeFromRecents to true in the manifiest prevents the app from being shown at all in the recent tasks. This would disrupt the user experience.
  • Using FLAG_SECURE results in a blank card on the recents tasks screen. (How do I prevent Android taking a screenshot when my app goes to the background?) I don't like the blank screen. However, I'll stick to this solution if there is no workaround.
  • Overriding onCreateThumbnail seems like the ideal solution but, unfortunately, doesn't work as it's currently not invoked by the OS :( (https://code.google.com/p/android/issues/detail?id=29370)

然后有一些我尝试过的变通办法,但是没有按预期工作:

And then there are some workarounds that I tried out but that didn't work as hoped:

  • 启动一个新活动,该活动在onPause中显示应用程序徽标,以便显示其屏幕截图,而不是实际活动的屏幕截图.但是新活动打开的时间太长,并且破坏了用户体验.
  • onPause中将活动的内容视图设置为应用程序徽标的图像.这对我来说似乎是一个很好的解决方案.不幸的是,最近任务屏幕的屏幕截图是在未指定的时间拍摄的.在测试过程中,按下"Home"按钮后,会在关闭应用程序之前迅速显示应用程序徽标,但生成的屏幕快照会在此之前不久显示活动.
  • 从窗口小部件(例如textView.setText(""))中删除敏感数据也具有刚才提到的屏幕截图计时问题.
  • Start a new activity that shows the app logo in onPause so that it's screenshot is shown instead of the actual activitie's one. But the new activity takes too long to open and it disrupts the user experience.
  • Set the activitie's content view to an image of the app logo in onPause. That seemed like a great solution to me. Unfortunately, the screenshot for the recent tasks screen is taken at an unspecified time. During testing the app logo quickly appears before the app is closed when pressing 'Home' but the resulting screenshot shows the activity a short time before that.
  • Removing the sensitive data from the widgets (e.g. textView.setText("")) has the same problem of screenshot timing just mentioned.

列出的变通办法有其他替代想法或解决方案吗?

Any alternative ideas or solutions to the listed workarounds?

推荐答案

几个月前,我出于与您相同的目的调查了此问题.

I looked into this a couple of months ago for the same purpose as you.

不幸的是,我不得不得出结论,那就是根本不可能.我浏览了android源代码并进行了确认.

Unfortunately, I had to conclude that it is simply not possible. I dug through the android source code and confirmed it.

  • android没有可让您自定义它的回调或方法(无论如何都可以).除了FLAG_SECURE之外,这部分代码也不接受任何输入或更改.
  • OnPause和类似的生命周期方法被称为为时已晚(屏幕截图已拍摄).所有暗示您将要进入后台的生命周期方法都为时已晚.
  • 您在最近的任务中看到的图像是实际的屏幕截图-因此不受您对视图所做的更改(为时已晚)的影响.这意味着您不能及时修改视图(例如使其不可见,用其他替换,添加SECURE_FLAG或视图的任何其他障碍).顺便说一句,这些图像可以在仿真器上的/data/system_ce/0/recent_images上找到.
  • 唯一的例外是使用FLAG_SECURE,这将防止截取应用程序的屏幕截图.我尝试在onPause中设置该FLAG,然后在onResume中将其删除,但是正如已经提到的,这些生命周期方法已经在截取屏幕截图后运行,因此完全没有效果.
  • There is no callbacks or methods from android that allows you to customize it (that works anyway). Besides FLAG_SECURE, this part of the code does not accept any input or change.
  • OnPause and similar lifecycle methods are called too late (the screenshot is taken already). All lifecycle methods that would hint that you're about to go into the background runs too late.
  • The image you see in the recent tasks is an actual screenshot - and thus isn't affected by changes you do (too late) to your view. That means you can't modify your view just-in-time (like making it invisible, replacing with something else, adding SECURE_FLAG, or any other obstruction of the view). As an aside, these images can be found on an emulator at /data/system_ce/0/recent_images.
  • The only exception is using FLAG_SECURE, which will prevent the screenshot from being taken of your application. I experimented with setting this FLAG in onPause and removing it in onResume, however as mentioned already these lifecycle methods runs after the screenshot is taken already, and thus had absolutely no effect.

如何更改显示的快照中所述通过最近的应用列表?曾经有一个回调可用于自定义缩略图:

As discussed in How to change the snapshot shown by recent apps list? there used to be a callback that you could use to customize the thumbnail: onCreateThumbnail. However, this does not work and it is never called. To be clear, the callback is still there, it is simply never called by the OS. The fact that it stopped working is poorly documented, but apparently was silently deprecated/removed in 4.0.3

至于缩略图本身,它是在服务器端截取的屏幕截图.在调用onPause之前(或者实际上在任何表示您的活动即将进入后台的回调之前)进行调用.

As for the thumbnail itself, it is a screenshot taken serverside. It is taken before onPause is called (or in fact before any callbacks indicating that your activity is about to go into the background is called).

当您的应用程序确实进入后台时,您的实际视图会被动画化(以实现缩小过渡).动画 可能会受到您在onPause中所做的更改的影响(如果您的速度足够快的话)(我尝试过在窗口中将不透明度设置为0).但是,这只会影响动画.动画制作完成后,该视图将替换为之前拍摄的屏幕截图.

When your app does go into the background, your actual view is animated (to get that zoom-out transition). That animation can be affected through changes you do in onPause (if you're fast enough that is) (I experimented with setting opacity to 0 on the window among other things). This will however only affect the animation. When the animation is finished, the view is replaced by the screenshot taken earlier.

也请参见讨论这些问题:

Also see these questions that discuss this:

  • When does Android take its recent apps switcher screenshot?
  • Show custom application image in task manager on ICS or JB
  • Android never call method onCreateThumbnail

这篇关于Android:自定义最近使用的应用缩略图(默认情况下为屏幕截图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆