【发布时间】:2012-03-26 15:33:05
【问题描述】:
我的旧诺基亚手机在未接电话时闪烁着硬件按钮。所以我能够理解我只是看电话就错过了一个电话。使用我的新 Android 手机时,我必须拿到手机并唤醒屏幕以查看是否有未接电话。
我搜索了 Android 市场,但找不到确切的应用程序来解决我的问题。所以我决定写它。问题是如何打开和关闭安卓手机硬件按钮的后盖?
我用谷歌搜索了它,但找不到一个干净的答案。
提前致谢。
【问题讨论】:
我的旧诺基亚手机在未接电话时闪烁着硬件按钮。所以我能够理解我只是看电话就错过了一个电话。使用我的新 Android 手机时,我必须拿到手机并唤醒屏幕以查看是否有未接电话。
我搜索了 Android 市场,但找不到确切的应用程序来解决我的问题。所以我决定写它。问题是如何打开和关闭安卓手机硬件按钮的后盖?
我用谷歌搜索了它,但找不到一个干净的答案。
提前致谢。
【问题讨论】:
Android 确实有 notifications 用于此目的,背光不被认为是通过 API 控制的(你可以在根设备上做到这一点,但那是另一回事)。
就我个人而言,我确实会收到未接电话通知,而且我的通知 LED 会闪烁。但是,您可以实现自己的通知:
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// create a new notification
CharSequence tickerText = "Missed call";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
// control how the notification led should behave
notification.ledARGB = 0xff00ff00;
// blink for 300ms every 1s
notification.ledOnMS = 300;
notification.ledOffMS = 1000;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
// usually you also want to create a PendingIntent and attach it
// with notification.setLatestEventInfo
// finally, post the notification to the notification manager
notificationManager.notify(HELLO_ID, notification);
还有许多其他通知选项,例如振动或FLAG_AUTO_CANCEL,但它们是documented very well ;-)
在有根设备上,您可以执行以下操作来控制背光(但是,我建议坚持使用预期的方式,即通知):
su
echo 25 > /sys/class/leds/button-backlight-portrait/currents
echo 25 > /sys/class/leds/button-backlight-landscape/currents
25 是亮度。但诚然,我不确定这是否适用于所有设备。
【讨论】: