I am using ionic storage in my app and It needs almost 1GB device space to launch the app.
If device memory is not having at least 1GB of space app will not be launched. After clearing that memory I am able to launch.
this the way, I am trying to save some data after signing-in into local storage.
const seq = this.api.post('signin', value).share();
seq.subscribe((res: any) => {
// If the API returned a successful response, mark the user as logged in
if (res.statusCode === 200) {
(window as any).FirebasePlugin.setUserProperty('loggedInUserId', res.user);
this.passwordMismatch = '';
this.invalidSinIn = false;
const isExistingUser = true;
// store details into ionic storage
Promise.all([this.storage.set('user', res.user), this.storage.set('token', res.token),
this.storage.set('isVerified', res.isVerified), this.storage.set('authType', 'email'),
this.storage.set('refreshToken', res.refreshToken), this.storage.set('referalCode', res.referalCode),
this.storage.set('existingUser', isExistingUser), this.storage.set('isProfileCompleted', res.isProfileCompleted)]).then(() => {
this.navCtrl.setRoot(MainPage);
});
}
});
This is working fine if the device is having available space of More then 1GB, but failing if memory is less.
Please help me to solve this issue. I am new in ionic
I am using
ionic framework: 3.9.2
Ionic App scripts: 3.1.2
Angular Core: 5.0.0
Related
Recently I publish my mobile application but there is a unique problem. In some devices people download application in google play and easily use the application. But some devices has need to clear all application data from settings then open again because if they don't do this they can't see onboarding screen and also can't fetch data from internet. In flutter I basically use Hive local storage at main dart to route after installation
//Here if onBoard box is true user will see welcomescreen
if (Hive.box('settings').get('onBoard') == true) {
screen = const WelcomeScreen();
}
//Here if user already registered but click sign out button isRegistered box will be false and user
//will go LoginPage again
else if(Hive.box('settings').get('isRegistered') == false){
screen = const LoginPageDesign();
}
//! If on boarding not true (false or null) user will route OnBoarding page
else {
screen = const OnBoarding();
}
The problem is some android devices backsup local storage data to the cloud. You can go through this article from android: https://developer.android.com/guide/topics/data/autobackup.html
So, to overcome this issue, just navigate to your AndroidManifest and do the following just under application tag:
<application
...
android:allowBackup="false"
android:fullBackupContent="false"
tools:replace="android:allowBackup"
...
</application>
switch(Hive.box('settings').get('isRegistered')){
case null:
screen = const OnBoarding();
break;
case false:
screen = const LoginPageDesign();
break;
case true:
screen = const WelcomeScreen();
break;
}
Interestingly once I tested with internal test,
Android 13 real devices has no problem it goes first onBoaring but with Android 10 it goes directly WelcomeScreen I don't understand how it is possible to take true for this situation should always null at fresh start.
EDIT : Problem is interestingly fixed once add another Hive.box for registeration ...
There is an application written in React. Images are loaded using the following code:
<input type='file' id='single-file' onChange={props.onChange}/>
onChange = e => {
let ua = navigator.userAgent;
let is_ie = ua.indexOf("MSIE ") > -1 || ua.indexOf("Trident/") > -1;
if (is_ie === true) {
let file = document.getElementById('single-file').files[0];
this.props.uploadImage(file);
this.props.openUpload(true);
} else {
this.props.uploadImage(e.target.files[0]);
this.props.openUpload(true);
e.target.value = '';
}
};
sent as standard with axios module using FormData.
When testing, it was found that from the PC, and Android phones, sending files happens quickly and normally. But on the iPhone on the mobile Internet of the network, the photo is sent perfectly, but it takes about two to three minutes with wi-fi. Different iPhones (X, XR, 6, 7), different browsers, different wi-fi networks were tested - the result is the same.
Maybe someone faced a similar problem?
I want to build some sort of offline app with some json data, i want fill my database when app's life cycle is first loading. i used pouchDb in ionic 2, i added PouchDB load plugin and its work fine with this code:
let PouchDB = require('pouchdb');
PouchDB.plugin(require('pouchdb-load'));
initDB() {
this._db = new PouchDB('cities3', { adapter: 'websql' });
this._db.load('../../../assessts/cities.json').then(function () {
console.log("Done loading!");
}).catch(function (err) {
console.log("error while loading!")
});
the output will be Done loading! but when i want to check the data in PouchDB inspector i will get this error:
No PouchDB found
To use the current page with PouchDB-Fauxton, window.PouchDB needs to be set.
i know that i should use window["PouchDB"] = PouchDB; but my question is, where?
You should add it after
this._db = new PouchDB('cities3', { adapter: 'websql' });
I'm using the Plugin.Media from #JamesMontemagno version 2.4.0-beta (which fixes picture orientation), it's working on Adroind 4.1.2 (Jelly Bean) and Marshmallow, but NOT on my Galaxy S5 Neo with Android version 5.1.1.
Basically when I take a picture it never returns back on the page from where I started the process; always returns back to the initial home page.
On devices where it works, when I take a picture, I see that first of all the application fires OnSleep, then after taking the picture fires OnResume.
On my device where is NOT working it fires OnSleep and after taking the picture doesn't fire OnResume, it fires the initialization page and then OnStart.
For this reason it doesn't open the page where I was when taking the picture.
What should I do to make sure it fires OnResume returning to the correct page and not OnStart which returns on initial fome page ?
In addition, when I take a picture it takes almost 30 seconds to get back to the code after awaiting TakePhotoAsync process, and it's too slow!
Following my code:
MyTapGestureRecognizerEditPicture.Tapped += async (sender, e) =>
{
//Display action sheet
String MyActionResult = await DisplayActionSheet(AppLocalization.UserInterface.EditImage,
AppLocalization.UserInterface.Cancel,
AppLocalization.UserInterface.Delete,
AppLocalization.UserInterface.TakePhoto,
AppLocalization.UserInterface.PickPhoto);
//Execute action result
if (MyActionResult == AppLocalization.UserInterface.TakePhoto)
{
//-----------------------------------------------------------------------------------------------------------------------------------------------
//Take photo
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
await DisplayAlert(AppLocalization.UserInterface.Alert, AppLocalization.UserInterface.NoCameraAvailable, AppLocalization.UserInterface.Ok);
}
else
{
var MyPhotoFile = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
Directory = "MyApp",
Name = "MyAppProfile.jpg",
SaveToAlbum = true,
PhotoSize = Plugin.Media.Abstractions.PhotoSize.Small
});
if (MyPhotoFile != null)
{
//Render image
MyProfilePicture.Source = ImageSource.FromFile(MyPhotoFile.Path);
//Save image on database
MemoryStream MyMemoryStream = new MemoryStream();
MyPhotoFile.GetStream().CopyTo(MyMemoryStream);
byte[] MyArrBytePicture = MyMemoryStream.ToArray();
await SaveProfilePicture(MyArrBytePicture);
MyPhotoFile.Dispose();
MyMemoryStream.Dispose();
}
}
}
if (MyActionResult == AppLocalization.UserInterface.PickPhoto)
{
//-----------------------------------------------------------------------------------------------------------------------------------------------
//Pick photo
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsPickPhotoSupported)
{
await DisplayAlert(AppLocalization.UserInterface.Alert, AppLocalization.UserInterface.PermissionNotGranted, AppLocalization.UserInterface.Ok);
}
else
{
var MyPhotoFile = await CrossMedia.Current.PickPhotoAsync();
if (MyPhotoFile != null)
{
//Render image
MyProfilePicture.Source = ImageSource.FromFile(MyPhotoFile.Path);
//Save image on database
MemoryStream MyMemoryStream = new MemoryStream();
MyPhotoFile.GetStream().CopyTo(MyMemoryStream);
byte[] MyArrBytePicture = MyMemoryStream.ToArray();
await SaveProfilePicture(MyArrBytePicture);
MyPhotoFile.Dispose();
MyMemoryStream.Dispose();
}
}
}
};
Please help!! We need to deploy this app but we cannot do it with this problem.
Thank you in advance!
It is perfectly normal to have the Android OS terminate and restart an Activity. As you are seeing, your app's Activity it will be automatically restarted when the camera app exits and the OS returns control to your app. The odds are it just needed more memory in order to take that photo with the Neo's 16MP camera, you can watch the logcat output to confirm that.
Restarted – It is possible for an activity that is anywhere from paused to stopped in the lifecycle to be removed from memory by Android. If the user navigates back to the activity it must be restarted, restored to its previously saved state, and then displayed to the user.
What to do:
So on the Xamarin.Forms OnStart lifecycle method you need to restore your application to a valid running state (initializing variables, preforming any bindings, etc...).
Plug code:
The Android platform code for the TakePhotoAsync method looks fine to me, but remember that the memory for that image that is passed back via the Task will be doubled as it is marshaled from the ART VM back the Mono VM. Calling GC.Collect() as soon as possible after the return will help (but your Activity is restarting anyway...)
public async Task<MediaFile> TakePhotoAsync(StoreCameraMediaOptions options)
{
~~~
var media = await TakeMediaAsync("image/*", MediaStore.ActionImageCapture, options);
In turn calls:
this.context.StartActivity(CreateMediaIntent(id, type, action, options));
Not much less you can really do within the Android OS to popup the Camera.
In addition, when I take a picture it takes almost 30 seconds to get back to the code after awaiting TakePhotoAsync process, and it's too slow!
Is that on your Neo? Or all devices?
I would call that very suspect (ie. a bug) as even flushing all the Java memory after the native Camera Intent/Activity and the restart time for your app's Activity should not take 30 seconds on a oct-core 1.6 GHz Cortex... but I do not have your device, app and code in front of me....
I'm developing an hybrid application using ionic.
Most of the features would work on mobile web browser. So the final product can be used from an http address as well. But there are certain code segments/features ( such as vibration, background alerts ) which will obviously be for the app version. And those features will only be available on the app version.
What's a good/recommended way to detect the current situation in the code base so that I can do logic such as if (isRunningAsApp) {do this} else {do that}*?
would it be just checking window.location.href and if you get something that starts wiih http:, then it is a mobile app, otherwise it is an app?
This is from Ionic's documentation
angular.module('PlatformApp', ['ionic']).controller('PlatformCtrl', function($scope) {
ionic.Platform.ready(function(){
// will execute when device is ready, or immediately if the device is already ready.
});
var deviceInformation = ionic.Platform.device();
var isWebView = ionic.Platform.isWebView();
var isIPad = ionic.Platform.isIPad();
var isIOS = ionic.Platform.isIOS();
var isAndroid = ionic.Platform.isAndroid();
var isWindowsPhone = ionic.Platform.isWindowsPhone();
var currentPlatform = ionic.Platform.platform();
var currentPlatformVersion = ionic.Platform.version();
ionic.Platform.exitApp(); // stops the app
});