Thank you for your response.You can create a semi-transparent activity. You will need to configure it to pass touch events. Start with implementing the transparent activity and if the results are good then I can help you with the touch events.
SetApplicationAttribute(android:theme, "@android:style/Theme.Translucent")
Dim jo As JavaObject = Activity
Dim Window As JavaObject = jo.RunMethodJO("getContext", Null).RunMethod("getWindow", Null)
Window.RunMethod("addFlags", Array As Object(524288)) 'FLAG_SHOW_WHEN_LOCKED
Window.RunMethod("addFlags", Array As Object(128)) 'FLAG_KEEP_SCREEN_ON
Window.RunMethod("addFlags", Array As Object(16)) 'FLAG_NOT_TOUCHABLE
I've tried but it didn't work.Try this code: https://www.b4x.com/android/forum/posts/422209
I try it on two samsung devices, a T113 (android 4.2.2) and a T280 (android 5.1.1)Works fine here. I see the yellow layer and can touch the screen. The activity is removed when you click on the home button.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Pass touch events to the background activity
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
...
setContentView(R.layout.main);
}
Why does this code create an exception?You can put the relevant code in the oncreate hook: https://www.b4x.com/android/forum/threads/inline-java-code.50141/#content
#if java
import android.view.WindowManager;
protected void _onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
}
#End If
Here it is:It will be easier to say if you post the exception.
Logger connected to: samsung SM-T110
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zerosoftbh.transparent/com.zerosoftbh.transparent.main}: java.lang.RuntimeException: java.lang.IllegalArgumentException: wrong number of arguments; expected 1, got 0
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
at android.app.ActivityThread.access$700(ActivityThread.java:158)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5365)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: wrong number of arguments; expected 1, got 0
at anywheresoftware.b4a.BA.runHook(BA.java:155)
at com.zerosoftbh.transparent.main.onCreate(main.java:58)
at android.app.Activity.performCreate(Activity.java:5326)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2225)
... 11 more
Caused by: java.lang.IllegalArgumentException: wrong number of arguments; expected 1, got 0
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.runHook(BA.java:152)
... 15 more
Yes, I read the "Wrong number of arguments, expected 1, got 0" message.The signature is wrong. See the example in the tutorial: https://www.b4x.com/android/forum/threads/inline-java-code.50141/#content
#if java
import android.view.WindowManager;
public void _onCreate() {
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
}
#End If
This is the closest I got: the transparent activity is running, shortcuts are clicked, but applications do not run.B4X:#if java import android.view.WindowManager; public void _onCreate() { getWindow().addFlags( WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); } #End If
Perhaps I am wrong, but to my understanding, this should be done with a new window which does not belong to the activity. It could be generated from a foreground service which will keep a reference to its instance. This way, the window will "survive" even when your activity is paused.
The drawback is that since Android 6, and on some devices before, drawing over other apps is seen as dangerous, so the permission has to be handled differently. Don't know if because it is a "special one", but it is not included in runtimePermissions library.
Try this example, which uses a workaround. I have tested it with Android 5.1 and 6.0 and works properly . Not sure if it will work with all devices.
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (oservice) Create ***
** Service (oservice) Start **
Error occurred on line: 27 (oService)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
at b4a.example.screenfilter.oservice._init_element(oservice.java:155)
at b4a.example.screenfilter.oservice._service_start(oservice.java:233)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at b4a.example.screenfilter.oservice.handleStart(oservice.java:107)
at b4a.example.screenfilter.oservice.access$000(oservice.java:15)
at b4a.example.screenfilter.oservice$1.run(oservice.java:78)
at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand(ServiceHelper.java:221)
at b4a.example.screenfilter.oservice.onStartCommand(oservice.java:76)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3679)
at android.app.ActivityThread.-wrap21(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1801)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@b00b775 -- permission denied for window type 2002
at android.view.ViewRootImpl.setView(ViewRootImpl.java:982)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:381)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:100)
at b4a.example.screenfilter.oservice$CustomImageView.sharedConstructing(oservice.java:276)
at b4a.example.screenfilter.oservice$CustomImageView.<init>(oservice.java:249)
at b4a.example.screenfilter.oservice.newInstance(oservice.java:287)
... 25 more