How to get statusbar insets for android app? - android

I'm trying to make my android app "edge to edge" (make statusbar and navbar translucent). I've read many articles online about this topic but since so many methods and classes are deprecated now, I tried to write it using new ways. The app runs Ok on my physical Samsung phone running android 11, but it gives me runtime error for getting insets while launching the app on my android studio emulator running android 10. Take a look at the code and error:
code (onCreateView() in mainFragment.kt):
binding.appbar.setOnApplyWindowInsetsListener { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsets.Type.statusBars())
view.updatePadding(top = insets.top)
windowInsets
}
error:
java.lang.NoSuchMethodError: No static method statusBars()I in class Landroid/view/WindowInsets$Type; or its super classes (declaration of 'android.view.WindowInsets$Type' appears in /system/framework/framework.jar!classes3.dex)
.MainFragment$onCreateView$1.onApplyWindowInsets(MainFragment.kt:44)
update: There is also no problem with an emulator running android 11! Now I think I had to do the job differently for lower APIs, but how exactly?!

Try to use the same method that you're using from the androidX lib.
ViewCompat.setOnApplyWindowInsetsListener(view, listener)

Related

Trying to use custom shader code in a class inheriting from QMaterial for Android

I'm trying to work around a bug inside a material class in the Extras for the Qt3D module:
https://bugreports.qt.io/browse/QTBUG-109574. I've trying to accomplish this, running on my Nokia G20 smartphone. I'm using Qt 6.2.4.
I believe the problem is that the wrong QTechnique is being used at runtime. Within the implementation for QPhongMaterial, there contains a few different techniques with graphics API filters for OpenGL and OpenGL/ES, versions 2 and 3, as seen here: https://github.com/qt/qt3d/blob/6.2.4/src/extras/defaults/qdiffusespecularmaterial.cpp.
To try and influence the QTechnique choice, I've tried to override the rendering API, and the surface format to be compatible with my smartphone:
QSurfaceFormat surfaceFormat;
surfaceFormat.setMajorVersion(2);
surfaceFormat.setMinorVersion(0);
surfaceFormat.setProfile(QSurfaceFormat::OpenGLContextProfile::NoProfile);
qputenv("QSG_RHI_BACKEND", "gles2");
I've also tried to make my own class derived from QMaterial, but that's another issue, as I'm getting a black screen in my viewport with that, which I can't fix, because the Android GPU Inspector doesn't support my device.

"Immersive Mode" Android app. All documentation is deprecated

I'm trying to make my app run in fullscreen mode where the navigation bar and the status bar is hidden. All documentation I can find seems to be deprecated and the only one that I could find that seemed to not be deprecated in Kotlin is setDecorFitsSystemWindows(false) but that errors with
java.lang.NoSuchMethodError: No virtual method setDecorFitsSystemWindows(Z)V in class Landroid/view/Window; or its super classes (declaration of 'android.view.Window' appears in /system/framework/framework.jar!classes3.dex)
How do you make an app fullscreen now in Android Kotlin?
There are one alternative solution.
Update androidx.core library
implementation "androidx.core:core-ktx:1.5.0-alpha05"
Instead of
activity?.window?.setDecorFitsSystemWindows(false)
Use new api
activity?.window?.run{
WindowCompat.setDecorFitsSystemWindows(this, false)
}

Android status bar show in Unty

I'm triyng to show the status bar in an Android phone using Unity. I have try this code:
void Start() {
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
But an error appear;
Assets/Scenes/Control/control.cs(15,34): error CS0103: The name 'WindowManager' does not exist in the current context
Does I need to call or import another package? Some could help me with this detail. Thanks in advance.
You cannot use Android Java functions directly in Unity. You can only use whats available in Unity C Sharp. Unity doesn’t understand the method. Suggested workaround, use a ‘Slider’ UI element and manipulate it in a custom c sharp script. Complicated workaround create a custom Unity Plugin which calls the native Android method (possible but complex).

Qt Android gesture issue

Upon writing a simple Android application in Qt, I encountered an uncomfortable dilemma:
I have a subclass of QWidget called PlotView, and have reimplemented the event-function from it:
bool PlotView::event(QEvent *event){
if(event->type() == QEvent::Gesture){
emit gestureEvent(static_cast<QGestureEvent*>(event));
return true;
}
return QWidget::event(event); \\Line A
}
Also I have the following lines in the class constructor:
this->grabGesture(Qt::SwipeGesture);
this->grabGesture(Qt::PanGesture);
this->grabGesture(Qt::PinchGesture);
this->setAttribute(Qt::WA_AcceptTouchEvents);
What I find very peculiar is that when running the application like this, it does not recognize any gestures. However, when removing the last line of the function (Line A above), the gestures are suddenly recognized, but the widget is not painted.
Some specs: I am currently running Qt 5.2.0, compiling on a Samsung Galaxy Note 10.1 GT-N8010 running Android 4.1.2.
Does anyone have any suggestions to how I could make this run with both the widget being painted and gesture recognition?
It seems adding the lines
this->grabGesture(Qt::SwipeGesture);
this->grabGesture(Qt::PanGesture);
this->grabGesture(Qt::PinchGesture);
this->setAttribute(Qt::WA_AcceptTouchEvents);
to the parent class constructor fixed the problem.

Honeycomb 3.1 / Mono for Android persist 'LightsOut'

I developed my app using Mono for Android. I have the latest version 4.0.3. My AndroidManifest.xml specifies:
<uses-sdk android:targetSdkVersion="11" android:minSdkVersion="8" />
The app runs on tablets, so in Honeycomb I need to hide the status bar at the bottom of the screen. This is how I do that (with a simple extension method):
internal static void LightsOut(this View view)
{
try
{
IntPtr view_setSystemUiVisibility = JNIEnv.GetMethodID(view.Class.Handle, "setSystemUiVisibility", "(I)V");
JNIEnv.CallVoidMethod(view.Handle, view_setSystemUiVisibility, new JValue(1));
}
catch
{ }
}
I call this on every view that I instantiate. On my Motorola Xoom, running 3.0.1, this works great.
On my Samsung Galaxy Tab running 3.1, it works; but the status bar comes back after some short period of time. In the Android Log I see that LightsOn() is getting called...
How can I prevent the status bar from coming back in 3.1? I saw this event:
http://developer.android.com/reference/android/view/View.OnSystemUiVisibilityChangeListener.html
And thought I could use it to hide the status bar, if it comes back. But I don't see how I can subscribe to it (it doesn't show in Intellisense).
Does something specific happen before the status bar comes back, or is it solely time related? A quick search of the ICS source suggests that the status bar status will be reset when the top App Window changes. Are you calling StartActivity() or moving to another app when you see this behavior?
The View.OnSystemUiVisibilityChangeListener interface has been bound as the View.IOnSystemUiVisibilityChangeListener interface and through the View.SystemUiVisibilityChange event. However, both of these mechanisms require that your $(TargetFrameworkVersion) target Android v3.1 or later, which would set your //uses-sdk/#android:minSdkVersion attribute to 12, and is thus something you (presumably) don't want to do.
I see two plausible solutions here:
Figure out why LightsOn() is being invoked and try to work around it (call LightsOut() within every Activity.OnCreate() method?).
Provide two versions of your app, one with a minSdkVersion of 8, and one of (at least) 12, and then use Multiple APK Support to include both in your program. The device will then run the appropriate package, permitting access to the View.SystemUiVisibilityChange event.

Categories

Resources