Hi!
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:
https://www.b4x.com/android/forum/threads/how-to-listen-monitor-clipboard-changes.42355/
https://www.b4x.com/android/forum/t...opy-initiate-intent-my-app.60688/#post-382941
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.
Maybe you have any ideas?
Thanks and have a sunny weekend!
Wolfgang
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:
https://www.b4x.com/android/forum/threads/how-to-listen-monitor-clipboard-changes.42355/
https://www.b4x.com/android/forum/t...opy-initiate-intent-my-app.60688/#post-382941
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.
B4X:
Sub Process_Globals
Dim R As Reflector
Dim Cjo As JavaObject
Dim ClipboardListener As Object
End Sub
Sub Service_Create
Dim CB As BClipboard
CB.clrText
SetClipListener
End Sub
Sub SetClipListener
Cjo = R.GetContext
Cjo = Cjo.RunMethod("getSystemService",Array As Object("clipboard"))
ClipboardListener = Cjo.CreateEvent("android.content.ClipboardManager.OnPrimaryClipChangedListener","ClipChanged",False)
Cjo.RunMethod("addPrimaryClipChangedListener",Array(ClipboardListener))
'!!! Does not work: !!!
Cjo.RunMethod("removePrimaryClipChangedListener",Array(ClipboardListener))
'!!! !!!!!!!!!!!!!! !!!
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!
Wolfgang