如何以编程方式打开/ Android中密切通知?

编程入门 行业动态 更新时间:2024-10-24 20:15:07
本文介绍了如何以编程方式打开/ Android中密切通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我到处找,却找不到在SDK或对谷歌如何做到的事。我知道这是可能的,因为所有的自定义发射器可以通过一个按钮preSS(的LauncherPro,ADW,等)。这样做

I've searched everywhere, but can't find anything in the SDK or on Google on how to do this. I know it's possible because all the custom launchers are able to do it via a button press (LauncherPro, ADW, etc).

感谢。

推荐答案

从阿斯温下面的Andr​​oid版本的Works的答案4.2.2(即低于版本17)。在4.2.2中,扩大​​的方式改为expandNotificationsPanel。如果不使用该方法名4.2.2及以上,你会得到一个空指针异常。因此,code应该是:

The answer from Ashwin works for Android versions below 4.2.2 (i.e. below version 17). In 4.2.2, the "expand" method was changed to "expandNotificationsPanel". If you don't use that method name for 4.2.2 and above, you will get a Null Pointer Exception. So the code should be:

Object sbservice = getSystemService( "statusbar" ); Class<?> statusbarManager = Class.forName( "android.app.StatusBarManager" ); Method showsb; if (Build.VERSION.SDK_INT >= 17) { showsb = statusbarManager.getMethod("expandNotificationsPanel"); } else { showsb = statusbarManager.getMethod("expand"); } showsb.invoke( sbservice );

和适当的权限应加入 AndroidManifest 。

<uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />

显然,这是不公布的API的一部分,所以这不能保证在今后的工作中,很多人会建议反对这样做。

Obviously, this is not part of the published API, so this is not guaranteed to work in the future and many people would advise against doing this.

更多推荐

如何以编程方式打开/ Android中密切通知?

本文发布于:2023-11-27 20:16:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639453.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   通知   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!