Ionic Storage is not working on Android device - android

I'm new to the Ionic Framework, and I'm doing an app that preserves the user login so it can show a different page when user is logged. And for doing this, I'm saving the user ID into the local storage.
This works fine when I do ionic serve and testing the code on browser, but it doesn't work on my Android device (so I run ionic cordova run android). Why? I have set the Storage right by using IonicStorageModule.forRoot() in app.module.ts -> imports[...]. Here's my code and my Ionic specs:

I just figured out my problem and built a solution. On the very first access in my app userLoggedID is completely empty (it wasn't neither undefined nor null), so I attached a catch() instruction and now the code works fine.
LOG:

Related

How can I run ionic-angular application that calls APIs as Android App on a device

I have built an ionic angular application that connects to an API end point. On the web browser it works well. I compiled it for Android platform and opened it on the Android studio. When I connect my phone to the PC and run the application, it opens the login page which by default loads when the application starts up. However, immediately upon starting up it is supposed to make an API call which loads the initialization data, it instead generates a message as shown in the image attached.
error from API call in ionic-angular app on android
I have tried to find out, but it seems that the API calls are being blocked as the initialization data is not retrieved from the remote server. I checked through and found some related problems but their solutions never worked for me. Some of the links I referred to are:
XMLHttpRequest failed on App
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/
https://stackoverflow.com/questions/54275697/ionic-4-app-not-working-in-android-device#:~:text=2%20Answers&text=Go%20to%20AVD%20manager%20in,android%20and%20it%20should%20work.&text=When%20I%20had%20this%20issue,use%20the%20'new'%20operator.
Could someone point me to some info that can help me fix this issue.
I am relatively new in Angular and Ionic programming and I don't have a experience in using raw JavaScript though I use TypeScript in Angular framework.
I was able to fix my issue with the help from the link
https://imstudio.medium.com/android-8-cleartext-http-traffic-not-permitted-73c1c9e3b803

How to clear Android app data in Cordova app

I'm using Phonegap Build for my application. I wonder is there any way to clear ALL app data (not just localStorage or cache) in my app? I have some problems with relogin in my app for Android. When I do localStorage.clear(), it seems like Android doesn't clean data. I also tried to clean cache at that moment (using cordova-plugin-cache-clear plugin). But if I clean app data manually (in phone`s settings) it works perfectly. Otherwise I have conflicts when I try to login again, as if Android use some old previous data. Other platforms work ok.
localStorage.clear should do it (I've used it successfully).
Normally I don't use it though, as (obviously) it cleans out everything.
So, for individual credentials, options and such I use localStorage.removeItem.
There's no need to clear the cache. localStorage calls have immediate effect, at least from the app's point of view.
Without seeing the login code it's hard to be more specific.
You can use this plugin to clear App data for Android and iOS apps:
https://github.com/dpa99c/cordova-plugin-clear-data
Another way, is using ionic framework. There is $ionicHistory.clearCache() which will clear app data.
When change the code and run in borwser by
cordova run browser
and haven't any change, then use:
cordova build
and run again:
cordova run browser

Cordova Url Loading Not Working

I am coding a Cordova application in Visual Studio. It is a hosted web app which means Cordova starts a webview with the local index.html and after deviceready, I redirect the document location to my locally hosted web url.
When I was testing on iPhone (iOS 9.3), I noticed that the Cordova app hangs/freezes at the splash screen after I rebuild the hosted web page. I thought it might be due to the latency occurring after compilation because it works in the successive trials. And I tried to debug using Visual Studio, attaching to the local device, and using the console I changed the url to test several sites. When response is immediate, no problem but when there is even about a second of latency, it does not navigate, but there seems no error in the Javascript Console of the Visual Studio debugger.
I know that there is a "loadUrlTimeout" parameter in the config.xml for Android but there is none for iOS. (I did not try it with Android if there is such a problem there too.) Am I doing something wrong? Is this the expected behavior? How can I fix it?

Android app works fine on web and on device through PhoneGap Desktop, but is just white screen on build.phonegap.com

This is my first time using build.phonegap.com. I have built an app that is entirely self-contained and doesn't use any connection or camera etc. It uses jquery, jquery mobile, HTML and CSS. It is a simple quiz that simply navigates through the DOM to verify the user input.
Here's what I do:
I use PhoneGap Desktop (on Windows) to generate the project and then add the code afterwards. I test it on my browser, then I test it on my device (Android) through Phonegap Desktop and then I zip up the folder (the project folder that was originally generated by phonegap desktop) and upload it to build.phonegap.com.
When I run it through the browser it works perfectly, with no error in the console.
When I run it though my device via PhoneGap Desktop, again, it runs perfectly.
When I upload it to build.phonegap.com, all seems to be fine (no issues in the debugger either). I run it my Android device via the QR-code-download and it installs with no issues.
When I open the app via build.phonegap.com, I just get a blank white screen.
I have checked my config.xml file and all the images and references are correct. All js and css files are referenced correctly (I've checked and it all works on my device via PhoneGap desktop and on my browser).
There are no js errors in the Chrome console.
I have feeling that I'm missing out something important. I haven't developed an app for a while a lot of the advice and tutorials seem to be out-of-phase with my project.
Can anyone help?
Many thanks,
Joe

Cordova features aren't work on server

I am a developer of DisciplineXgames! We are developing a mobile app. We have downloaded the Cordova test suite from here (https://github.com/apache/cordova-mobile-spec). When I upload this on DisciplineXgames server it shows an error in alert box "Error: Apache Cordova did not initialize. Demo will not run correctly." but when we upload the same folder on Phonegap server it works perfectly fine. Unfortunately this doesn't solve our problem as we are building our mobile app on our server and just using Phonegap to redirect the user to the page hosted on DisciplineXgames server if there's Internet in the user's mobile.
First error which I got in the console area in Google Chrome is cordova.js missing when I provided that than it outputs another error that is cordova/channel is required.
Hope you can guide us through how we can use Cordova's amazing features on our server instead of Phonegap's local server.
I am a bit confused as to what you are trying to accomplish here but I am going to take a stab.
You want to develop an app that when the app launches, it checks to see if the device has internet connectivity. If it does, then the app just opens the mobile website hosted on your servers. if there is no internet connectivity then the app ???
Since this is a very simple use case for an app, I would avoid using cordova and instead use PhoneGap Build. Simply write an index.html page and a .js file to check for the connectivity and then use the inappbrowser plugin to open your mobile site if there is connectivity. Once that is done, zip your package, upload to phonegap build and then download your compiled apps.
phoneGap Build allows you to avoid the app building overhead and the need to install things BUT prevents you from taking advantage of some of the deeper configurations and some plugins. But again, for your simple use case, PhoneGap Build sounds like the way to go.

Categories

Resources