I'm having an issue with some android devices when changing the font-size display setting through configuration.
In web browser my app is simple ignoring this. This is true for some other mobiles too.
But with some specific mobiles (like Motorola G or X) changing this config also affects my Phonegap app.
I don't know how to avoid this to make the app look consistent
I've found a solution using this cordova plugin: com.phonegap.plugin.mobile-accessibility
You have to follow installation instructions for the plugin, and then you can use it inside Ionic app. You only have to ensure to call its functions after Cordova 'deviceready' callback (accesed by $ionicPlatform.ready in the example below):
angular.module('app').controller('IndexController', function ($ionicPlatform, $window) {
$ionicPlatform.ready(function(){
if($window.MobileAccessibility){
$window.MobileAccessibility.usePreferredTextZoom(false);
}
});
});
For anyone using Ionic. Documentation is here.
Install
$ ionic cordova plugin add phonegap-plugin-mobile-accessibility
$ npm install --save #ionic-native/mobile-accessibility
Add to module, i.e. app.module.ts
import { MobileAccessibility } from 'ionic-native';
#NgModule({
providers:[MobileAccessibility]
});
In app.component.ts
constructor( mobileAccessibility: MobileAccessibility, platform: Platform) {
platform
.ready()
.then(()=>{
mobileAccessibility.usePreferredTextZoom(false);
});
}
Related
I'm using capacitor v3 beta and there are no problem working in web and iOS but can't run android app.
Build is done fine but when running the app appears this error:
E/Capacitor/Console: File: http://localhost/vendor-es2015.js - Line 41296 - Msg: ERROR Error: Uncaught (in promise): Error: "Storage" plugin is not implemented on android
Error: "Storage" plugin is not implemented on android
To solve this error I've removed the storage plugin and replaced with ionic/storage plugin. But when I use other plugin, for example the Keyboard, the error shows up saying that Keyboard plugin is not implemented on android.
So I suppose that there is some problem with Android builds or project configuration.
These are de node dependencies in my package.json
"#capacitor/android": "^3.0.0-beta.6",
"#capacitor/core": "^3.0.0-beta.1",
"#capacitor/storage": "^0.3.1",
And my capacitor.config.json file
{
"appId": "net.flowww.me",
"appName": "FLOWwwMe",
"bundledWebRuntime": false,
"npmClient": "npm",
"webDir": "www",
"cordova": {}
}
iOS version works well with this configuration.
Storage plugin not worked after Ionic v3 upgrades from v2.
It work after manually adding a plugin to MainActivity.java for me:
package com.ionic.app;
import android.os.Bundle;
import com.getcapacitor.BridgeActivity;
import com.capacitorjs.plugins.storage.StoragePlugin;
public class MainActivity extends BridgeActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
registerPlugin(StoragePlugin.class);
}
}
I also faced the same problem when upgrading from capacitor 2 to 3
As it turned out, I forgot to execute:
npx cap sync android
This solved the problem
you must in mainActivity : add(StoragePlugin.class);
After creating new project and reviewing file differences saw that I have not installed
"#capacitor/cli": "^3.0.0-beta.6"
So I installed it and all compiles successfully.
In Capacitor's v2 doc, in the page dedicated to Storage Plugin (https://capacitorjs.com/docs/apis/storage) the import is done like:
import { Storage } from '#capacitor/storage';
Then in the Capacitor's v2 doc for Using Plugins (https://capacitorjs.com/docs/v2/apis) you'll find that:
Import the Plugins object. It represents the registry of all Capacitor plugins.
import { Plugins } from '#capacitor/core';
Get a plugin from the Plugin Registry (Plugins object).
const { Browser } = Plugins;
Use the plugin API:
async openBrowser() {
// On iOS, for example, open the URL in SFSafariViewController (the in-app browser)
await Browser.open({ url: "https://ionicframework.com" });
}
A common mistake is to import a plugin directly, then use the plugin API >immediately, resulting in the web implementation being used:
import { Browser } from '#capacitor/core';
async openBrowser() {
// On iOS, for example, this will open the URL in Safari instead of
// the SFSafariViewController (in-app browser)
await Browser.open({ url: "https://ionicframework.com" });
}
By using the plugins from the plugin registry (Plugins object), the native implementation of the plugin is used (if available), with fallback to the web version.
So if you're using Quasar with Capacitor v2 you probably gone crazy like me. Just replace Browser with Storage.
Maybe in v3 that problem is solved and that's why legomolina's answer works.
For Capacitor V3 plugins (tested on Android 11 & Ionic 5)
capacitor.plugins.json has the entry for Storage plugin,
MainActivity.java should not have the onCreate function, where CapV3 uses native API,
Try setting minifyEnabled=false in build.gradle.
If error disappears, create pro-guard rules in proguard-rules.pro as in https://github.com/ionic-team/capacitor/issues/739
I found the issue was solved by simply starting up Android Studio. It sync'd Gradle automatically and then I just restarted my Android dev environment - the error was gone and I was able to access Storage as per the capaitor plugin docs.
See https://capacitorjs.com/docs/android/troubleshooting#plugin-not-implemented
i'm trying to implement Code-Push from AppCenter into my Ionic v4 App. (ref)
I'm stuck on the following Problem: I can update the App, but when i close the App after that and open again it is the old Version again and it says:
Updade ignored, because it was rollbacked
So somehow the update is rolled back after i close the App. After searching for this problem i found that i have to run
this.codePush.notifyApplicationReady()
on application start. I added this to my code, but it doesn't work either. If i run the Application on a Android Emulator and open the Logs, AFTER the Update it says:
cordova_not_available
So it makes sense that the notifyApplicationReady doesn't work, but why is cordova unavailable?
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.codePush.notifyApplicationReady().then(value => {
console.log(value);
});
this.codePush.sync({
deploymentKey: 'MY_KEY',
installMode: InstallMode.IMMEDIATE
}).subscribe(status => {
console.log(status);
});
this.splashScreen.hide();
});
}
Do u use command ionic build --prod ? this conmand will not include cordova.js,so if app installed this package the cordova will not available, in ionic4 i use ionic cordova build android --prod to include the cordova.js and then release the www file to code push serve.it wokrs!
My app is under Ionic 4 for android and I have to open/run/launch external app (for exemple com.google.android.youtube or com.sygic.truck) -> for instance, any installed app.
I tested many options without any success :
InAppBrowserModule (using application://my.package.name).
Cordova plugin lampaa (I didn't find any ways to use it under angular/ts app type).
I tried also webIntent using package option and action option calling the main Activity.
For InAppBrowserModule, i'm stuck with the http:// protocole appended before my app url.
For Lampaa, i'm stuck with the undefined startApp (even after following other threads suggestions).
And for webIntent, I don't think that it's relevent for my issue.
Any suggestions ?
Thanks in advance !
[EDIT]
I finally make it works !
You can use one of those 2 lines :
this.iab.create('android-app://com.google.android.youtube',"_system");
window.open('android-app://com.google.android.youtube',"_system");
You can replace com.google.android.youtube by any application package name !
You can check if the user is on Android, have the app installed and later open it as follow:
constructor(
private platform: Platform, // from 'ionic-angular'
private appAvailability: AppAvailability, // from '#ionic-native/app-availability'
private iab: InAppBrowser, // from '#ionic-native/in-app-browser'
) {}
openYoutube() {
const package = "com.google.android.youtube"
if(this.platform.is('android')) {
this.appAvailability.check(package)
.then(()=> {
this.iab.create('android-app://'+package, '_system', 'location=yes')
})
.catch(()=> {
// not installed
)
} else {
// not on Android
}
}
For ionic 4 we can use
ionic cordova plugin add cordova-plugin-app-launcher
npm install #ionic-native/app-launcher
You can use the following cordova plugin to check if other apps are installed and launch them.
ionic cordova plugin add cordova-plugin-app-launcher
npm install #ionic-native/app-launcher
Simple Cordova plugin to see if other apps are installed and launch them.
I want to get the android device language from the app developed using Ionic3, Cordova and Angular4.
How can I get it?
window.navigator.language worked for me with no plugin. I didn't check to see how the results compare to the Globalization plugin, but I got results like: Android: "en-us", "es-us" and on iOS: "en-US" and "es-XL"
also see https://stackoverflow.com/a/4079798/431296 -window.navigator.userLanguage wasn't defined on either Android or iOS, so I didn't include it
You can use cordova-plugin-globalization which also offers an ionic-native wrapper. It offers a lot of useful methods, but you are probably looking for getPreferredLanguage() or getLocaleName().
Installation:
ionic cordova plugin add cordova-plugin-globalization
npm install --save #ionic-native/globalization
Example:
import { Globalization } from '#ionic-native/globalization';
constructor(private globalization: Globalization) {
this.globalization.getPreferredLanguage()
.then(res => console.log(res))
.catch(e => console.log(e));
}
Follow up to David's answer, the Globalization API is deprecated.
With the ECMA Internationalization API now supported on iOS, Android and Windows devices, this plugin is not required any more.
* Migrating from this plugin to the ECMA Internationalization API is explained in this Cordova blog post.
If you're using ngx-translate,
import { TranslateService } from '#ngx-translate/core';
constructor(private translate: TranslateService) {
console.log(this.translate.getBrowserLang());
}
works fine on the devices and in the browser. It's returning "en" or "de".
For ionic 5 with capacitor:
npm install #capacitor/device
npx cap sync
in code:
import { Device } from '#capacitor/device';
console.log((await Device.getLanguageCode()).value); // en-US
https://capacitorjs.com/docs/apis/device
Ionic 4
In Ionic we call it Globalization performs operations specific to the user's locale, language, and timezone.
Installation : Terminal
ionic cordova plugin add cordova-plugin-globalization
npm install #ionic-native/globalization
Usages: Any Component or service file.
import { Globalization } from '#ionic-native/globalization/ngx';
constructor(private global: Globalization) { }
...
this.global.getPreferredLanguage()
.then(res => console.log(res))
.catch(e => console.log(e));
I am trying to enable my phone bluetooth via ionic app. I am calling something like this:
cordova.plugins.locationManager.enableBluetooth()
But not enabling and making any error also. Following is my app.js code. Please help out.
import {App, Platform} from 'ionic-framework/ionic';
import {TabsPage} from './pages/tabs/tabs';
#App({
template: '<ion-nav [root]="rootPage"></ion-nav>',
config: {} // http://ionicframework.com/docs/v2/api/config/Config/
})
export class MyApp {
static get parameters() {
return [[Platform]];
}
constructor(platform) {
this.rootPage = TabsPage;
platform.ready().then(() => {
StatusBar.backgroundColorByName('red');
console.log("App starting.");
cordova.plugins.locationManager.enableBluetooth();
});
}
}
Is there anything I am missing. My phone is One Plus One.
UPDATE:
Is there any particular configuration I have to in device to achieve
this in develop mode
App technical info
Ionic 2 & Angular 2
Plugin : com.unarin.cordova.beacon (Link)
I resolved this myself. Seems to be issue was with petermetz/cordova-plugin-ibeacon, I was using 25days older plugin.
First removed the existing plugin by running by going into project root folder:
sudo cordova plugin rm com.unarin.cordova.beacon
Then again added the plugin (basically I updated my plugin):
sudo cordova plugin add https://github.com/petermetz/cordova-plugin-ibeacon.git
After that everything started working fine.
Thanks.