Show status bar in Android in PhoneGap app (ie prevent fullscreen) - android

I have a phonegap 3.0.0 application.
My application covers the status bar (the thing with the clock, reception info, etc). Since i'm not a full screen game, this is not desirable.
I believe it's running as a "Full Screen" app.
I've found posts here on stack to do the opposite (ie make an app go full screen) and did the inverse of what was suggested. I'm wondering if something changed in PhoneGap or perhaps the PhoneGap CLI that I used to create the project because my app is showing fullscreen.
I tried this:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen", R.drawable.splash);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
super.loadUrl(Config.getStartUrl(), 10000);
}
Which explicitly tells it to NOT be in full screen mode.... but it still shows up full screen.

The native code suggested above will work, but a cleaner way would be just to make sure you don't have in the config.xml:
<preference name="fullscreen" value="true" />
you can also set it to "false", but its actually the default value so its not necessary. works for me.

I figured it out.
The Splashscreen plugin must be setting it to fullscreen.
By calling the clearFlags method AFTER super.loadUrl, once the app loads the status bar shows up.
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen", R.drawable.splash);
super.loadUrl(Config.getStartUrl(), 10000);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

make this change in res/xml/config.xml on eclipse.
<preference
name="fullscreen"
value="false" />

// Hide status bar
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Show status bar
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
The default behavior should be NOT fullscreen, have you modified your theme in xml?
Some other code I have found, just in case:
private void toggleFullscreen(boolean fullscreen)
{
WindowManager.LayoutParams attrs = getWindow().getAttributes();
if (fullscreen)
{
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
}
else
{
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
}
getWindow().setAttributes(attrs);
}

Related

Cordova - StatusBar hidden at launch - Android

I'm using Cordova's StatusBar and SplashScreen. I want the app to launch fullscreen i.e. status bar to be hidden when the app launches.
In the deviceready callback, I'm invoking StatusBar.hide() and later on I use StatusBar.show() to show the status bar again. This works fine.
The issue is when the splash image appears, the status bar is visible. And when the deviceready callback if fired, the status bar hides. I even tried setting Fullscreen preference in config.xml to true, but the result is same. Hide at Startup configuration is also related to iOS only.
Is there a way (using Cordova only) to launch the app without status bar and show it later on?
Note: I'm using SplashScreen plugin to show splash screen
Find MainActivity.java in
\platforms\android\app\src\main\java\com\yourpackage\name
add this to the import section :
import android.view.WindowManager;
then add this code to the last line :
public class MainActivity extends CordovaActivity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// enable Cordova apps to be started in the background
Bundle extras = getIntent().getExtras();
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
moveTaskToBack(true);
}
// [Hyuck] add this two line below
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
}
// [Hyuck] onStart() is totally new.
#Override
public void onStart()
{
super.onStart();
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
}
this is snippet from Hyuck answer on :
Ionic 3 - Hide status bar during splash screen show
it's do the job for me.

is it possible to hide the system bar

I created a launcher, to use it in an internal application. for some security reasons i would like to hide the system bar (the acces to the parameter an ordrer to the acces to installed application). But i have no idea how to do this.
Tablet that will be used are not rooted.
Can you help me please?
You can't hide it but you can disable it, except home. For that you can give your application as home category and let the user choose.
<category android:name="android.intent.category.HOME" />
Rest all can be disable.
add this in manifest.
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>
inside onCreate()
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_home);
View v = findViewById(R.id.home_view);
v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
where home_view is the parent view of xml file.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return false;
}
public void onWindowFocusChanged(boolean hasFocus)
{
try
{
if(!hasFocus)
{
Object service = getSystemService("statusbar");
Class<?> statusbarManager = Class.forName("android.app.StatusBarManager");
Method collapse = statusbarManager.getMethod("collapse");
collapse .setAccessible(true);
collapse .invoke(service);
}
}
catch(Exception ex)
{
}
}
You can hide the bottom bar I used this code to hide:
getWindow().getDecorView().setSystemUiVisibility(View.GONE);
use this code for android box with keyboard or remote.
Tablet that will be used are not rooted
Then you can't hide it. You can however use SYSTEM_UI_FLAG_HIDE_NAVIGATION to hide it temporary, but it will get visible once the user touches the screen:
There is a limitation: because navigation controls are so important,
the least user interaction will cause them to reappear immediately.
When this happens, both this flag and SYSTEM_UI_FLAG_FULLSCREEN will
be cleared automatically, so that both elements reappear at the same
time.
You can hide the navigation bar on Android 4.0 and higher using the SYSTEM_UI_FLAG_HIDE_NAVIGATION flag. This snippet hides both the navigation bar and the status bar:
View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions
See the following: Hiding the Navigation Bar
Put this in your onCreate() method:
requestWindowFeature(Window.FEATURE_NO_TITLE);
EDIT: Hiding the status bar would require your application be full screen or rooted.

Hide the Android Notification bar on a Sencha Touch 2 app

I've successfully got my application compiled into an apk file, and deployed to my Android devices.
But when I run it there, the notification bar is present and I'd like it to be fullscreen, without the notification bar.
This is the bar at the top of the screen, with the battery usage, wifi/3G connection, new email icon, etc.
How do we hide this in our compiled apps with Sencha Touch 2?
I have set fullscreen: true in the config of the first view which is loaded (the log in screen), and have also set:
Ext.application({
viewport: {
autoMaximize: true
}
});
You could change this in your AndroidManifest.xml:
<application>
<activity
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
</activity>
...
</application>
You can actually modify the AndroidManifest.xml template in the SenchaCmd to get this, as explained in the Sencha forums.
That file will be in Sencha/Cmd/<CmdVersion>/stbuild/st-res/android/AndroidManifest.xml. You need to set the theme property on the application tag like this: android:theme="#android:style/Theme.NoTitleBar"
with the whole tag looking like:
<application android:icon="#drawable/icon" android:label="%s" android:theme="#android:style/Theme.NoTitleBar">
However, this solution is still extremely crappy and I'd love to see something that works without patching Sencha's code.
Simply add this to make the screen fullscreen this.setTheme(android.R.style.Theme_NoTitleBar_Fullscreen); before super.onCreate(savedInstanceState);
OR
add this.requestWindowFeature(Window.FEATURE_NO_TITLE); and
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN) before setContentView
For example:
#Override
public void onCreate(Bundle savedInstanceState){
/**sets Theme and Style (must be set BEFORE super.onCreate)*/
this.setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
OR
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
/**Changes Window. Removes title and/or notification bar (must be set BEFORE setContentView)*/
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
(Or you can do it via the Manifest as what homer_simpson said.)

How to disable status bar / notification bar on android programmatically?

i create a lockscreen application.. this application is triggered by SMS.. when a SMS containing command was received, it will display a lock screen activity.
my lockscreen activity is using TYPE_KEYGUARD for disabling a home screen button. When device screen turn off and then i turn it on again, my problem is status bar / notification bar still appear on my screen. this is a problem because the user still can access some program through status bar / notification bar even the device is being locked. so i want to dissapear this status bar / notification bar so that the user (theft) can't access that device anymore..
Please help me to solve this..
I think what you're trying to do is programmatically set an activity as fullscreen. If so, consider the following:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Source: http://www.androidsnippets.com/how-to-make-an-activity-fullscreen
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
}
requestWindowFeature(Window.FEATURE_NO_TITLE);
only disables the activity's title bar, not the notification bar at the top.
Use this theme in android manifest for your activity :
"Theme.NoTitleBar.Fullscreen"
did work for me.
It hides the notification bar.
On Android 4.0 and lower
Option 1:
<application
...
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen" >
...
</application>
Option 2:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// If the Android version is lower than Jellybean, use this call to hide
// the status bar.
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.activity_main);
}
...
}
on Android 4.1 and Higher
View decorView = getWindow().getDecorView();
// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
ActionBar actionBar = getActionBar();
actionBar.hide();
And for Android 4.6(Api 19) and higher use the Immersive Full-Screen
Mode
Reference from Google

"No such resource" setting activity's theme

I want to display a picture full screen without an action bar in Android tablet, but when I write android:theme="#android:style/Theme_NoTitleBar_Fullscreen" in Android Manifest, it says there is no such resource. How is it possible since it is on the list of themes?
You should use:
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
you can use this
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

Categories

Resources