Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:从服务中检测触摸_Android_Service_Background_Touch_Screen - Fatal编程技术网

Android:从服务中检测触摸

Android:从服务中检测触摸,android,service,background,touch,screen,Android,Service,Background,Touch,Screen,我试图找到一种方法来检测当我的服务在后台运行时,用户以任何方式触摸屏幕。例如,我希望能够检测用户何时按下主屏幕上的应用程序图标。这可能吗?如果可能,将如何实施?请参阅服务说明。您应该能够使用Messenger向您的服务发送消息。所以在你的onClick活动中,你将呼叫你的messenger。。。例如: try { Message msg = Message.obtain(null, MessengerService.

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

请参阅服务说明。您应该能够使用Messenger向您的服务发送消息。所以在你的onClick活动中,你将呼叫你的messenger。。。例如:

        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.
        }
可能会派上用场: