我希望创建一个简单的服务(在后台运行),当用户从浏览器或短信等复制任何内容时,会有一个弹出消息显示这个文本。
我有这段代码,可以在来电时显示弹窗。
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();
}
}
}
}
还有在 manifest.xml 中的这段代码
<action android:name="android.intent.action.PHONE_STATE"></action>
现在这段代码告诉我们将任何手机状态发送到myreciever
类,现在我想从剪贴板管理器中获取文本。是否有任何intent.action
状态可以在有人复制文本时调用myreciever
类。
任何形式的帮助或代码都将不胜感激。