TranslateApp icon indicating copy to clipboard operation
TranslateApp copied to clipboard

app外悬浮窗如何覆盖状态栏讨论

Open leizhiyuan opened this issue 8 years ago • 7 comments

参考1里的尝试情况

TYPE_SEARCH_BAR:未知 TYPE_ACCESSIBILITY_OVERLAY:拒绝使用 TYPE_APPLICATION:只能配合Activity在当前APP使用 TYPE_APPLICATION_ATTACHED_DIALOG:只能配合Activity在当前APP使用 TYPE_APPLICATION_MEDIA:无法使用(什么也不显示) TYPE_APPLICATION_PANEL:只能配合Activity在当前APP使用(PopupWindow默认就是这个>Type) TYPE_APPLICATION_STARTING:无法使用(什么也不显示) TYPE_APPLICATION_SUB_PANEL:只能配合Activity在当前APP使用 TYPE_BASE_APPLICATION:无法使用(什么也不显示) TYPE_CHANGED:只能配合Activity在当前APP使用 TYPE_INPUT_METHOD:无法使用(直接崩溃) TYPE_INPUT_METHOD_DIALOG:无法使用(直接崩溃) TYPE_KEYGUARD_DIALOG:拒绝使用 TYPE_PHONE:属于悬浮窗(并且给一个Activity的话按下HOME键会出现看不到桌面上的图标异常情况) TYPE_TOAST:不属于悬浮窗,但有悬浮窗的功能,缺点是在Android2.3上无法接收点击事件 TYPE_SYSTEM_ALERT:属于悬浮窗,但是会被禁止

可以看到这个TOAST的type是不能改的.要改申请权限,如果申请权限,就不用通过这种方式绕过了, 根据官方说明

type: 值低的窗口在值高的下层,相同的 type值,后创建的窗口显示在先创建的窗口上面.

但是状态栏是2000

Window type: the status bar. There can be only one status bar window; it is placed at the top of the screen, and all other windows are shifted down so they are below it. In multiuser systems shows on all users' windows.

TYPE_TOAST 是 2005 然后就是可能修改FLAG了.

我自己根据官方文档.测试了几个比较可能的.比如 FLAG_FULLSCREEN 等.当时这个值的时候,会被状态栏遮挡部分,但是无法显示在状态栏之上.( ,说法好像有冲突..按理说应该是在上面的.因为值更高.也可能是因为这个值只能在本app内使用.)

暂无思路..

leizhiyuan avatar Mar 28 '16 00:03 leizhiyuan

可以看看这个项目 https://github.com/zzz40500/HeadsUp

maoruibin avatar Mar 28 '16 05:03 maoruibin

好,有空了看看~

On Mon, Mar 28, 2016 at 1:11 PM, 咕咚 [email protected] wrote:

可以看看这个项目 https://github.com/zzz40500/HeadsUp

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/maoruibin/TranslateApp/issues/12#issuecomment-202237385

leizhiyuan avatar Mar 28 '16 05:03 leizhiyuan

看了一下这个项目,基本原理就是使用Notification

TipViewController中的show方法中,先简(hen)单(cuo)的demo测试一下,.

  Intent openintent = new Intent();
        PendingIntent contentIntent = PendingIntent.getActivity(GDApplication.get(), 0, openintent, 0);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                GDApplication.get()).setSmallIcon(android.R.drawable.ic_lock_power_off).setPriority(2)
                .setContentTitle(result.getQuery())
                .setContentText(result.getExplains().get(0))
                .setFullScreenIntent(contentIntent,true);
        NotificationManager mNotifyManager = (NotificationManager) GDApplication.get().getSystemService(Context.NOTIFICATION_SERVICE);

        int id=NOTIFY_ID++;

        mNotifyManager.notify(id, mBuilder.build());
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        mNotifyManager.cancel(id);

实现的效果是,app外可以显示,2s后自动取消. demo 取消后通知栏干净 demo2

剩下的问题是

  1. 添加并响应收藏按钮,
  2. 兼容问题,是否直接使用HeadsUp这个项目.

leizhiyuan avatar Mar 30 '16 00:03 leizhiyuan

https://github.com/zzz40500/HeadsUp 这个项目也看了下,小米的MIUI系统,不能弹出悬浮窗,有个权限问题。现在想做好像qq微信那有的桌面顶部消息提示,有没有大神知道怎么兼容MIUI吗?

df13954 avatar Feb 07 '17 06:02 df13954

如果是 6.0 以上的系统,可以通过申请权限,获取一个 可以让应用悬浮在其他应用之上的权限,参考 http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2016/0118/3882.html 看这个能不能解决你的问题

maoruibin avatar Feb 07 '17 06:02 maoruibin

但是,这样子6-的机型,就无法实现好像qq微信那有提示消息了。不知道有没有大神做过啊。最近几天一直在找这个东西

df13954 avatar Feb 07 '17 06:02 df13954

WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; 可以遮住状态栏,并且状态栏无法拉下来

sbbqq avatar Mar 27 '18 09:03 sbbqq