安卓:实现广播接收器ClipboardManager [英] Android : Implement Broadcast Receiver for ClipboardManager

查看:422
本文介绍了安卓:实现广播接收器ClipboardManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个监听器,会听,如果一些复制任何东西从任何应用程序。

I want to implement a listener which will listen if some copied any thing from any application.

我听到关于 ClipboardManager.OnPrimaryClipChangedListener()将听取复制动作,但这不是一个接收器(据我所知)。我有一个示例应用程序,逻辑背后这个应用程序是,开始从系统启动服务,并运行它会听复制操作的服务,但我认为这会耗尽电池。我对吗?

I heard about ClipboardManager.OnPrimaryClipChangedListener() which will listen copy action, but this is not a Receiver (As I understand). 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.

推荐答案

下面是监听器:

class ClipboardListener implements ClipboardManager.OnPrimaryClipChangedListener
{
   public void onPrimaryClipChanged()
   {
      // do something useful here with the clipboard
      // use getText() method
   }
}

刚刚注册:

ClipboardManager clipBoard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
clipBoard.addPrimaryClipChangedListener( new ClipboardListener() );

这篇关于安卓:实现广播接收器ClipboardManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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