How to minimise app in ionic using capacitor - android

I want to minimise the app on pressing back button in my ionic application that uses capacitor. (To be clear, what i mean by minimise is to trigger the action of 'middle back button' on pressing of 'edge back button'. I hope that this is clear in reference to majority of the android phones.). I found something similar in cordova, (https://ionicframework.com/docs/native/app-minimize). But my application crashes while using it. So is there any capacitor alternative to the same?

Related

Cordova hide screen from recent activity list on Android

Is there a way in Cordova to clear the screen before the app goes into the recent activity list on Android?
I'm making a game where I don't want the user to be able to see the playfield during a pause. So I need to switch visuals or something before the app ends up in the recent activity list.
At the moment I'm listening for the 'pause' event from Cordova, but even if I render the canvas once more at this point (or even remove it entirely) this new state won't show on the recent app list and instead still shows the previous frame.
I've seen some banking apps have this behavior so it should be possible somehow.
PS: I'm using PIXI as framework but I assume that's of no concern here.
I finally found the solution via this blog post: https://medium.com/#lakshaydulani/hybrid-app-horror-hiding-the-screenshot-in-app-switcher-82c318a350bf
Apparently there is a Cordova plugin that does exactly what I need: https://github.com/devgeeks/PrivacyScreenPlugin
Just install and compile the app.. Sweet!

Add native functionality to hybrid apps

We have an Ionic app where we want to add a new feature in native. So clicking a button in the app, will launch a plugin just like normal plugins with it on UI etc. However complication comes when I want to navigate freely back and forth from plugin side to Ionic.
Consider these scenarios:
Plugin to open a HTML page written on Ionic side based on a user
action. Clicking back on this html page will again land you back to plugin UI.
Maintaining back stack in Ionic and Android/iOS side so that back navigation happens smoothly.
What I did so far is to use sendPluginResult method to pass different codes to Ionic side and open desired pages. In reality it destroys the back stack totally since plugin has exited.
Clicking back button on Ionic side, I actually make plugin method calls again kind of emulating back behavior.
Is there a better way to handle this? Has someone faced similar problems?
I hope that I understood your question correctly.
Assuming that you can use some variable to check whether this plugin just opened a html-page, you could do something like this:
$ionicPlatform.registerBackButtonAction(function(event) {
if(/* check if plugin just opened html-page here */){
// if condition succeeds, then do not open same html-page again
event.preventDefault();
// go two steps backwards to prevent this plugin to open same html-page again
history.go(-2);
// update your variable
// ...
}
},100);
Hope it helps.

Phonegap 2.6 android inappbrowser opens on self despite _blank being passed

I am using PhoneGap 2.6.0 with Sencha Touch 2.2 on Android 4.0.3. I am calling the InAppBrowser to open a share url to facebook like so:
window.open(encodeURI('https://www.facebook.com/sharer/sharer.php?u=http://www.mycoolapp.com/&t=Everyone check this out'), '_blank', 'location=no');
However, instead of opening the InAppBrowser with the UI, it opens on top of my app screen without any 'OK' button like on iOS or any way to close and go back.
I am able to go back with the standard Android OS back button.
Is there any way to get the url bar and the OK button to show on the Android InAppBrowser for PhoneGap?
As per window.open section in docs, you have to give `location=yes' to show location bar. Regarding type of window, do you see any difference when you pass '_self' and '_blank'?
Maybe a problem with your Access-origin in res/xml/config.xml (PhoneGap 2.6.0 Domain Whitelist Guide)...?
As others stated, for android you have to specify location=yes and no you can't get riddle of the location bar and mantain back button.
But if you are on Android why do you have to keep it?
Being able to coming back with physical back button is the preferred behaviour by design in Android.

in Cordova 1.8.1 - Android history.back() not working

I am developing a phonegap application in which the app loads the external url(http://example.com) into webview. When I navigate through the screen using window.location.href. I cant able to go back to the previous screen using the soft back button that present in the webview itself.
The android hard back button closes the back(which is fine for now).
Can anyone help me out.
It is the same problem: If jquery mobile does not create history entries, the back-button from the android phone will terminate the app, because, there is no Activity to go back to.
If you go forwrd through your app, make a pushState: https://developer.mozilla.org/en-US/docs/DOM/Manipulating_the_browser_history
If you have history entries, your app will not close and hopefully the soft-back button will work.

Pause an Android App with Phonegap

Is there any way to programmatically pause an Android app in Phonegap? I would like to mimic the behavior that occurs when you hit the HOME button. I've already had to overwrite the back button handler using this, and while in most cases I want it to do my action, when in a particular state the user would expect the app to minimize, and I want to replicate this behavior.
Keep in mind, on Android this is not the same as closing the app. That is quite easy to do with device.exitApp(); but I would like it to remember its state and keep running in the background. Especially if there's still an asynchronous job being done in the background.
Is there a feature in Phonegap to achieve this?
Possible duplicate of Manually pause an application in Android Phonegap, but I couldn't find some of the tools the OP mentioned there such as navigator, so I was nervious to totally edit and rewrite their post
The simple answer appears to be: no.
However, for anyone else that comes down this path, its not impossible. It's just that there isn't a feature of Phonegap to do it for you.
The Android equivalent of "sleeping an app" is actually just opening another intent. Specifically, opening the "Home" intent would sleep the running app and bring you back to the home screen. But as far as I can tell from asking around and scoping the docs, Phonegap doesn't have a direct way of opening intents.
What you (supposedly) can do is one of two things:
This plugin is supposed to be promising
Call the Java code that does it yourself using the means described here
Mind you, as of right now I've decided to not go any further with this, so I make no promises about either of those means, having not attempted them myself.
I invite anyone else who decides to pursue this further to update their experience here.

Categories

Resources