Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
leizhiyuan opened this issue Mar 28, 2016 · 7 comments
Open

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

leizhiyuan opened this issue Mar 28, 2016 · 7 comments

Comments

@leizhiyuan
Copy link
Collaborator

参考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内使用.)

暂无思路..

@maoruibin
Copy link
Owner

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

@leizhiyuan
Copy link
Collaborator Author

好,有空了看看~

On Mon, Mar 28, 2016 at 1:11 PM, 咕咚 notifications@github.com 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
#12 (comment)

@leizhiyuan
Copy link
Collaborator Author

看了一下这个项目,基本原理就是使用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这个项目.

@df13954
Copy link

df13954 commented Feb 7, 2017

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

@maoruibin
Copy link
Owner

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

@maoruibin maoruibin reopened this Feb 7, 2017
@df13954
Copy link

df13954 commented Feb 7, 2017

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

@sbbqq
Copy link

sbbqq commented Mar 27, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants