How to close mobile app programmatically using IONIC 5? - ionic-framework

How to close the mobile app programmatically using IONIC 5? Use case: Upon app start, I am displaying a Terms of Use popover and if the user does not accept, I need to close the app. I am using IONIC5+Angular.
Thank you.
V

I figured it out.
While navigator['app'].exitApp() works for Android, it does not work for iOS. Also, according to Apple, the apps should not terminate themselves. For my app, I will just display the "Accept" but. The user will need to close the app manually if they don't want to agree to the Terms of Use.

navigator['app'].exitApp();
**that's work for me **
you also use
#capacitor/app
App.exitApp();
Force exit the app. This should only be used in conjunction with the backButton handler for Android to exit the app when navigation is complete.
Ionic handles this itself so you shouldn’t need to call this if using Ionic.

HTML :-
<ion-button color="danger" (click)="close()" fill="clear" expand="block">Close App </ion-button>
TS :-
import { Platform } from '#ionic/angular';
constructor(private platform: Platform) { }
close(){
this.platform.backButton.subscribe( () => {
navigator['app'].exitApp();
})
}

Related

How can I programatically close an ionic app?

I've tried the two following approaches to close my ionic app but non has worked.
1.
closeApp(){
this.platform.backButton.subscribeWithPriority(999999, () => {
navigator['app'].exitApp();
})
}
In this approach, when I click on the back button, the app is disappeared, but it's in the list of the background running apps. This doesn't help me, because I need the app to be completely closed and the user be forced to reopen the app by clicking on its icon.
2.
closeApp(){
const { App } = Plugins;
App['exitApp'];
}
in this case, nothing happens, i.e., I stay on the page.
Is there any other approach or plugin which I can use?
I am working with capacitor: 3 and testing on android 12.
import { App } from '#capacitor/app';
ExitApp() {
App.exitApp();
}
try this

Is there any way to show splashScreen when app is in the background or switching tabs. In ionic 6?

I use privacy-screen plugin to hide content when app is in the background, but it shows just gray background. I need to set splashScreen instead. Any suggestions?
I tried splashScreen plugin, but it is not working for me.
I don't know if it's the best way but I think that using Capacitor appStateChange from #capacitor/app (documentation) you could show and hide a screen with your logo when app is in background or foreground.
import { App } from '#capacitor/app';
App.addListener('appStateChange', ({ isActive }) => {
console.log('App state changed. Is active?', isActive);
if(!isActive) showLogoScreen();
else hideLogoScreen();
});
I hope it helps :)
For iOS, I did it simply in native code: just find the "applicationWillResignActive" method in AppDelegate and insert a view on top of the window.
For Android, sadly I couldn't find a better solution. The "gray background" you described is likely the implementation of Hide screen in 'Recent Apps List', but allow screenshots

How to disable Android back button in ionic 3 pwa app

I am working on progressive web app with ionic 3 and angular 6 framework.
Every thing works fine but when I press my browser back button or mobile back button my application get closed.
I tried to search how to do this, I am able to disable browser back button with java script but on mobile app it's not working.
<script>
// window.onbeforeunload = function() { return "Your work will be lost.";
};
$ionicPlatform.registerBackButtonAction(function (event) {
event.preventDefault();
}, 100);
</script>
I tried to register the back button event and lot's more but none of that is worked fine for me.
Can anyone have same issue then please tell me how to resolve this.
Thanks,
Dattatray
You can use Ionic's Platform to override the physical back button on Android.
Add it into app.component.ts file as such :
import { Platform } from 'ionic-angular';
constructor(public plt: Platform) {}
platform.registerBackButtonAction(() => {
//Add your code here
},100);
Ionic Platform Service.

How to add a shortcut to mobile homescreen in Xamarin.Forms?

How can I add a shortcut icon to mobile homescreen in Xamarin.Forms ?
I am a beginner in Xamarin and try to do this.
Edit:
Currently I don't have attached an Mac for IOS, yet
so what I want is to run only Droid for now
If you deploy your Android application via the Android play store, the shortcut will be added to the home screen automatically.
For iOS, it should get added by default when you install the app.
Add the following attribute to your Activity-class:
[Activity (MainLauncher=true)]
public class MainActivity: FormsApplicationActivity {
// ...
}
That should be all. For iOS there is no special action required.

Flex-Mobile: Should I use the menu-stuff provided or is it better not to because the iphone does not have a menu button?

I would not have asked the question if I owned an iphone, but so far I only have an android phone for development.
The question is: Should I use the View.viewMenuItems that are provided by flex mobile? Or should I better embed the functionality in another way? I don't know what possibilities might exist on iphone to open the menu, because it has no hardware button "menu".
By the way: How could I open the menu in the Flash-Builder mobile device emulator - there are no buttons, too....
Thanks!
you can detect the Menu Button through KeyBoardEvent in Android. In Iphone, the Home Button will exit out your application, so you should do some interface buttons to show your menu.
private function _onAddedToStage(event:FlexEvent):void
{
//removes listener
removeEventListener(Event.ADDED_TO_STAGE, _onAddedToStage);
stage.addEventListener(KeyboardEvent.KEY_DOWN, _onKeyDown);
}
private function _onKeyDown(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.MENU)
{
event.preventDefault();
_text.appendText("\nMenu Pressed");
}
}
The latest versions of Android's Honeycomb OS does not support the menu button. So if you do take advantage of Flex's ViewMenu feature beware that if you build using Flex 4.6 or newer there won't be a button on the latest Android Tablets and iOS devices.
In ADL you can choose Device > Menu to simulate clicking a hardware menu button.