我想创建一个简单的在后台运行的 service。当有人从浏览器或sms中复制任何文本资料时,就会有一个toast显示该文本。
我用的以下代码来实现当有电话时,就会给出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();
}
}
}
}
在manifest.xml
<action android:name="android.intent.action.PHONE_STATE"></action>
现在这段代码发送任何电话状态到myreciever类。我想从clipboard manager中获取文本。当有人复制一些文本时,是否有intent.action状态可以调用myreciever类?
请教这个问题,提供任何的代码或建议都非常感谢!