【问题标题】:Android: Detect touch from serviceAndroid:检测来自服务的触摸
【发布时间】:2011-08-09 18:43:37
【问题描述】:

我正在尝试找到一种方法来检测用户何时在我的服务在后台运行时以任何方式触摸屏幕。例如,我希望能够检测用户何时按下主屏幕上的应用程序图标。这可能吗?如果可以,如何实施?

【问题讨论】:

标签: android service background touch screen


【解决方案1】:

请看this服务说明。您应该能够使用 Messenger 向您的服务发送消息。因此,在您的 onClick 事件中,您将调用您的信使...例如:

        try {
            Message msg = Message.obtain(null,
                    MessengerService.MSG_BUTTON_CLICKED);
            msg.replyTo = mMessenger;
            mService.send(msg);

            // Give it some value as an example.
            msg = Message.obtain(null,
                    MessengerService.MSG_SET_VALUE, this.hashCode(), 0);
            mService.send(msg);
        } catch (RemoteException e) {
            // In this case the service has crashed before we could even
            // do anything with it; we can count on soon being
            // disconnected (and then reconnected if it can be restarted)
            // so there is no need to do anything here.
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    • 1970-01-01
    • 2022-06-18
    • 2013-07-06
    • 2012-04-18
    相关资源
    最近更新 更多