Show or hide the Android Status Bar in NativeScript

I was trying to get the status bar to hide in one of the apps and created a simple code to do that.

var application = require('application').android;
function statusBar(action){
    var activity = application.startActivity;
    //activity.runOnUiThread(function(){
    var win = activity.getWindow();
    if(action === 'hide'){
        win.addFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
    } else if(action === 'show'){
        win.clearFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
}

Then call statusBar('show') or statusBar('hide') in your pageloaded event.