Well, I do not really know how to explained but will try
So I have a service that under certain conditions put a panel on screen covering all the screen (later I will have to put a image on the panel but that will be another question...)for any aplication runnning (so it is a with the manifest
AddPermission(android.permission.SYSTEM_ALERT_WINDOW)...and so on)so it does not matter if my activity is runnning or not the panel will overlay the fullscreen ...(yes it can be annoying for the user but so far I do not care, it will be only a few secs until another condition is meeted)
I did it like this:
then in the same sub inside the service under other conditions the panel should be removed with this code
but this give the error:
r.RunMethod4("removeView",Array As Object (ScreenShot),Array As String( "android.view.View"))
java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:402)
at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:304)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:79)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:216)
at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod4(Reflection.java:857)
at b4a.example.zephyrservice._gesture_ontouch(zephyrservice.java:329)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at flm.b4a.gesturedetector.GestureDetectorForB4A$1.onTouch(SourceFile:86)
at android.view.View.dispatchTouchEvent(View.java:7456)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2264)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1995)
at android.view.View.dispatchPointerEvent(View.java:7641)
at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3682)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3613)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4804)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4783)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4875)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:174)
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4854)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4894)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:530)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735),,,bla bla bla
BTW:all the dim (specially the panel one) are inside the same sub and out of any if/then
I think that the problem is that this function when start keep looking for the false condition continuesly so I guess every time a "dimmed" the panel I loose the reference.....But As I need/want a service for this cannot "dimmed" a Panel on ProcessGlobals(I know would be much easier to do it in an activity...but not interested on doing it like that)
Any sugestion the get the right view¿?¿
PS:I read somewhere in the forum that getViewById does not work..
Many thanks in advanced
So I have a service that under certain conditions put a panel on screen covering all the screen (later I will have to put a image on the panel but that will be another question...)for any aplication runnning (so it is a with the manifest
AddPermission(android.permission.SYSTEM_ALERT_WINDOW)...and so on)so it does not matter if my activity is runnning or not the panel will overlay the fullscreen ...(yes it can be annoying for the user but so far I do not care, it will be only a few secs until another condition is meeted)
I did it like this:
B4X:
Dim r As Reflector
r.Target = r.GetContext
Dim cwm As Object = r.RunMethod2("getSystemService", "window", "java.lang.String")
Dim ScreenShot As Panel
ScreenShot.Initialize("ScreenShot")
ScreenShot.Color=Colors.ARGB(33,0,255,0)
Dim layoutParameters As Object
Dim i As String = "java.lang.int"
layoutParameters = r.CreateObject2("android.view.WindowManager$LayoutParams", Array As Object(widthPixels, heightPixels, 0, 0, 2007,8+32+256+262144,-3), Array As String(i, i, i, i, i, i,i))
r.Target = cwm
r.RunMethod4("addView", Array As Object(ScreenShot, layoutParameters),Array As String("android.view.View", "android.view.ViewGroup$LayoutParams"))
then in the same sub inside the service under other conditions the panel should be removed with this code
B4X:
r.Target = cwm
r.RunMethod4("removeView",Array As Object (ScreenShot),Array As String( "android.view.View")
but this give the error:
r.RunMethod4("removeView",Array As Object (ScreenShot),Array As String( "android.view.View"))
java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:402)
at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:304)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:79)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:216)
at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod4(Reflection.java:857)
at b4a.example.zephyrservice._gesture_ontouch(zephyrservice.java:329)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at flm.b4a.gesturedetector.GestureDetectorForB4A$1.onTouch(SourceFile:86)
at android.view.View.dispatchTouchEvent(View.java:7456)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2264)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1995)
at android.view.View.dispatchPointerEvent(View.java:7641)
at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3682)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3613)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4804)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4783)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4875)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:174)
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4854)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4894)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:530)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735),,,bla bla bla
BTW:all the dim (specially the panel one) are inside the same sub and out of any if/then
I think that the problem is that this function when start keep looking for the false condition continuesly so I guess every time a "dimmed" the panel I loose the reference.....But As I need/want a service for this cannot "dimmed" a Panel on ProcessGlobals(I know would be much easier to do it in an activity...but not interested on doing it like that)
Any sugestion the get the right view¿?¿
PS:I read somewhere in the forum that getViewById does not work..
Many thanks in advanced