Android Question Can't disable Clipboard-Listener

W. Graf

Licensed User
Longtime User

I'm sorry for having a new question because I don't want to waste your time. But I can't find an answer for this problem...:

I want to program a clipboard-listener. I found two interesting threads about this:

Based on these threads, I wrote my own listener/monitor and it works fine! Only one problem: I can't disable it!

The Android-method addPrimaryClipChangedListener() enables the monitor. So my app gets a notification about every change in the clipboard.
But the methode removePrimaryClipChangedListener() does not work. If I call it, my app still gets the notifications.
I tried it on Android 4.3 (Samsung Galaxy S3) and Android 4.4.2 (Samsung Galaxy S4 mini). Same results.
There are many java-source-codes on the Internet, but I can't test it (I can't program in Java).

See below my source code (located in Service-module 'starter').
Only for testing, I'm calling the add- and removePrimaryClipChangedListener-method successively. In my real app, the call of the remove-method would be in another Sub.

Sub Process_Globals
    Dim R As Reflector
    Dim Cjo As JavaObject
    Dim ClipboardListener As Object   
End Sub

Sub Service_Create
    Dim CB As BClipboard

End Sub

Sub SetClipListener
    Cjo = R.GetContext   
    Cjo = Cjo.RunMethod("getSystemService",Array As Object("clipboard"))

    ClipboardListener = Cjo.CreateEvent("android.content.ClipboardManager.OnPrimaryClipChangedListener","ClipChanged",False)
    '!!! Does not work: !!!
    '!!! !!!!!!!!!!!!!! !!!
End Sub

Sub ClipChanged_Event(MethodName As String, Args() As Object)
    ToastMessageShow("Clip-Change-Event fired!", True)
End Sub

Maybe you have any ideas?

Thanks and have a sunny weekend!