i have made app listens copies user makes in other apps , pastes text activity. service use listening copies works great recognizing copied text when want send broadcast activity, "onreceive" method not called.
this service code listening , sending data activity:
@override public int onstartcommand(intent intent, int flags, int startid) { cm = (clipboardmanager) getsystemservice(clipboard_service); cm.addprimaryclipchangedlistener(this); return start_sticky; } @override public void onprimaryclipchanged() { string copiedtext = cm.gettext().tostring(); mydynamictoast.informationmessage(getapplicationcontext(), copiedtext); intent sendcopy = new intent(getapplicationcontext(), createnoteactivity.class); sendcopy.putextra("copiedtext", copiedtext); localbroadcastmanager.getinstance(getapplicationcontext()).sendbroadcast(sendcopy); }
and @ activity:
private val receivecopy = object : broadcastreceiver() { override fun onreceive(context: context?, intent: intent?) { log.d("acreceiver", "called") val copiedtext = intent?.getstringextra("copiedtext") mydynamictoast.informationmessage(context, "copied text is:" + copiedtext) } } override fun onresume() { super.onresume() localbroadcastmanager.getinstance(this).registerreceiver(receivecopy, intentfilter(".services.clipboardservice")) } override fun onpause() { super.onpause() localbroadcastmanager.getinstance(this).unregisterreceiver(receivecopy) }
as can see have registered , unregistered broadcast receiver onreceive method not called. have missed here? thank you.
Comments
Post a Comment