java - Can't catch clipboard event in a background service android -
i'm trying catch clipboardchanged event in background service
public class mainactivity extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); intent = new intent(mainactivity.this, translateservice.class); startservice(i); } } public class translateservice extends intentservice implements clipboardmanager.onprimaryclipchangedlistener { public translateservice() { super(null); } public translateservice(string name) { super(name); clipboardmanager manager = (clipboardmanager) getsystemservice(clipboard_service); manager.addprimaryclipchangedlistener(this); } @override protected void onhandleintent(intent intent) { } @override public void onprimaryclipchanged() { toast.maketext(this, "working", toast.length_long).show(); } }
it should make toast "working" if event fired. tried create clipboardmanager , add listener in onhandleintent , didn't work either. ideas?
when default constructor called, not adding listener clipboardmanager
.
i think meant use this(null)
in default constructor instead of directly calling super(null)
.
public translateservice() { this(null); }
Comments
Post a Comment