android剪贴板广播接收器

Ior*_*ori 8 clipboard service android

当任何用户从浏览器或短信等中复制任何内容时,我想制作一个简单的服务(将在后台运行),会有一个toast显示该文本

我有这个代码,当有电话时给予吐司

public class MyPhoneReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        Bundle extras = intent.getExtras();

        if (extras != null) {

            // this code is for to accept the telephone call
            String state = extras.getString(TelephonyManager.EXTRA_STATE);
            if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                String phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
                Toast.makeText(context, phoneNumber, Toast.LENGTH_SHORT).show();
            }
        }   
    }
}
Run Code Online (Sandbox Code Playgroud)

和manifest.xml中的这段代码

<action android:name="android.intent.action.PHONE_STATE"></action>
Run Code Online (Sandbox Code Playgroud)

现在这段代码告诉myreciever我现在要向班级发送任何电话状态我想从剪贴板管理器获取文本.当有人复制文本时intent.action,是否有任何可以调用myreciever类的状态.

任何形式的帮助或代码将不胜感激.

cod*_*e22 14

由于剪贴板现在有Action意图,因此您需要创建一个广播接收器,以便在设备首次启动时启动应用程序时启动.然后启动服务以监视剪贴板的状态.

这是一个关于谷歌代码的完美项目,它将向您显示完整的操作.

我的剪辑教程