[英]Android : Implement Broadcast Receiver for ClipboardManager
I want to implement a listener which will listen if some copied any thing from any application.我想实现一个监听器,如果有人从任何应用程序复制了任何东西,它就会监听。
I heard about ClipboardManager.OnPrimaryClipChangedListener()
which will listen copy action, but this is not a Receiver (As I understand).我听说ClipboardManager.OnPrimaryClipChangedListener()
会监听复制动作,但这不是接收器(据我所知)。 I got a sample application , logic behind this application is, start service from system boot and run a service which will listen Copy action, but I think this will drain the battery.我得到了一个示例应用程序,该应用程序背后的逻辑是,从系统启动启动服务并运行一个将侦听复制操作的服务,但我认为这会耗尽电池电量。 Am I right?我对吗?
So how can I implement a Broadcast receiver which can listen Copy action.那么如何实现一个可以监听复制操作的广播接收器。
Here is the listener:这是听众:
class ClipboardListener implements ClipboardManager.OnPrimaryClipChangedListener
{
public void onPrimaryClipChanged()
{
// do something useful here with the clipboard
// use getText() method
}
}
Just register it:只需注册它:
ClipboardManager clipBoard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
clipBoard.addPrimaryClipChangedListener( new ClipboardListener() );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.