如何以编程方式打开/ Android中密切通知? [英] How can I programmatically open/close notifications in Android?

查看:149
本文介绍了如何以编程方式打开/ 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中密切通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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