"Immersive Mode" Android app. All documentation is deprecated - android

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)
}

Related

How to get statusbar insets for android app?

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)

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).

React Native - "ProgressBarAndroid is deprecated. Use ActivityIndicator instead"

I'm running into the error: "ProgressBarAndroid is deprecated. Use ActivityIndicator instead" but when I go to the docs, it doesn't look like it's actually deprecated.
I'm using
react-native-cli: 2.0.1
react-native: 0.40.0
Here's my current related code:
import React from 'react';
import { ProgressViewIOS, ProgressBarAndroid, Platform } from 'react-native';
export default function ProgressBar(props) {
if(Platform.OS === 'ios'){
return (
<ProgressViewIOS
progress={props.progress}
style={{height: 3}}
progressViewStyle={'bar'}
progressTintColor={props.progressTintColor}
/>
)
}else if(Platform.OS === 'android'){
return <ProgressBarAndroid styleAttr="Horizontal" progress={props.progress} />
}else{
console.log('NO PROGRESS')
return null
}
}
Even though I specify styleAttr="Horizontal" (which I believe should set indeterminate as false) my progress bar in android is indeterminate (it just keeps moving). This is not the same functionality I see on iOS. iOS works as expected.
Another error says "You are manually calling a React.PropType validation function for indeterminate prop on ProgressBarAndroid, however as you see in my code that is not the case. I also don't believe there is a third party doing this as the project is small and I haven't seen this error until I implemented as shown above:
Any help appreciated.
If it's warning you that it's deprecated why not just use the API its suggesting? What use case do you have that you feel it's necessary to use ProgressViewIOS over the component that it's being replaced by? (Especially since ActivityIndciator works on both iOS and Android)
To answer your question it may not be deprecated in the docs, but it is warning you that it has been deprecated in favor of the new API. You can continue to use it if you wish, but you won't get any updates and it may be removed in future versions.

MVP-Mosby-Api10: NoSuchMethodError android.support.v4.app.FragmentActivity.isChangingConfigurations

I get this error on crashlytics panel:
Fatal Exception: java.lang.NoSuchMethodError
android.support.v4.app.FragmentActivity.isChangingConfigurations
com.hannesdorfmann.mosby.mvp.MvpFragment.shouldInstanceBeRetained (MvpFragment.java:91)
com.hannesdorfmann.mosby.mvp.delegate.MvpInternalDelegate.detachView (MvpInternalDelegate.java:70)
com.hannesdorfmann.mosby.mvp.delegate.FragmentMvpDelegateImpl.onDestroyView (FragmentMvpDelegateImpl.java:73)
com.hannesdorfmann.mosby.mvp.MvpFragment.onDestroyView (MvpFragment.java:106)
com.hannesdorfmann.mosby.mvp.MvpFragment.shouldInstanceBeRetained (MvpFragment.java:91)
I override manifest for library to use it with api level 10 and I already test it on android 2.3.3 and it was working ok! but now I see this crash on crashlytics. Hi I can fix this for my version? is crash related to api 10? because the method is for support v4 library so I can't understand why this occurred.
yes the method isChangingConfigurations() has been introduced with API 11:
https://developer.android.com/reference/android/app/Activity.html#isChangingConfigurations()
as part of theandroid.app.Activity plattform class (and not as part android.support.v4.app.FragmentActivity, but FragmentActivity extends Activity).
Hence, this won't work on API < 11.
You could implement isChangingConfigurations() in your Activity and either call
super.isChangingConfigurations() if API >=11 or implement your own thing if (API < 11). You may want to take a look at Activities source code, but I'm not sure how this could be back ported. https://github.com/android/platform_frameworks_base/blob/master/core/java/android/app/Activity.java#L5152
You could try to just return false if API < 11 . That would mean that the View's state (and Presenter) will not survive screen orientation changes. DISCLAIMER: That might also cause some other unwanted side effects I'm not aware of right now and could break with any future release of Mosby or support library.

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