I have created a simple app in Ionic that uses Native Audio to play a single MP3-file. The code:
export class MyApp{
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, private nativeAudio:NativeAudio) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
this.nativeAudio.preloadComplex('24', 'assets/klamydihahaha.mp3',1,1,0.1).then(
(data)=>{
alert(data);
this.nativeAudio.play('24',()=>{alert("done")});
},(error)=>{
alert(error);
}
)
});
}
}
I run this on my Sony Xperia-device with Android 6.0 using
ionic cordova run android --device
The alert-message will first show "ok", it will wait and then the message "done" will show. But there is no sound. The MP3 file works fine. What can be the problem?
May be the cordova API is not included with your command
Instead type this command
ionic cordova run android --emulator
or
ionic cordova emulate android
Related
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!
I am new to Ionic 2 and everything around. I'm tryng to setup my first mobile app: touching a button I would open native navigation (Google Maps for Android, for instance). I've installed launchnavigator plugin:
ionic plugin add uk.co.workingedge.phonegap.plugin.launchnavigator
and inside cremony.ts page:
import { Component } from '#angular/core';
import { NavController } from 'ionic-angular';
import { LaunchNavigator, LaunchNavigatorOptions } from 'ionic-native';
#Component({
selector: 'page-ceremony',
templateUrl: 'ceremony.html'
})
export class Ceremony {
constructor(public navCtrl: NavController) {
}
navigate() {
let options: LaunchNavigatorOptions = {
start: ""
};
LaunchNavigator.navigate("London, UK", options)
.then(
success => alert('Launched navigator'),
error => alert('Error launching navigator: ' + error)
);
}
}
make a build npm run buildand upload it to IonicView with ionic upload.
I've do everything like suggested in this link but with different luck.
But when I click the button (a simple <button ion-button (click)="navigate()">Navigate</button> in the ceremony.html) in the Ionic View an error say: Error launghing navigator: plugin_not_installed.
I inspected the project, the plugins directory contains uk.co.workingedge.phonegap.plugin.launchnavigatorlooks directory. So I look at package.json and config.xml and I've added the value uk.co.workingedge.phonegap.plugin.launchnavigator in the cordovaPlugins
and tag <plugin name="uk.co.workingedge.phonegap.plugin.launchnavigator" spec="~3.2.1" /> in the widget root. npm run build, ionic upload but nothing changed.
Where is my error?
New answer, there is something wrong with your project. Have you modified your index.html file? Is it still including cordova.js? If so what version of Ionic and Cordova are you using?
I made this sample application with your exact code and it works perfectly on both iOS and ANdroid: https://github.com/roblouie/navigator-plugin-test
Did a screen recording on iOS: https://giphy.com/gifs/xTiN0EEQV82aIXWnQI
Just grabbed an image on Android, but it works the same:
Please try the project from github.
Cordova plugins need to be called only once platform is ready.
constructor(public navCtrl: NavController,public platform:Platform) {//inject in constructor
}
In your function navigate()
this.platform.ready().then(()=>{
LaunchNavigator.navigate("London, UK", options)
.then(
success => alert('Launched navigator'),
error => alert('Error launching navigator: ' + error)
);
});
The reason for your error is that you are using Ionic View. Your Ionic app is just html, css, and javascript. However, any plugins you use are written in Java for Android and Objective C for iOS. That plugin source code is then compiled into your app for each platform.
With Ionic View, it only uploads your app, the html, css, and javascript. Nothing is compiled. Ionic View is the app itself, and it loads your code. So no plugins you have are included. Ionic View itself does have some plugins installed on it, and you can see that list here: https://docs.ionic.io/tools/view/#supported-plugins
Unfortunately you will not be able to test any plugin not in that list without building and deploying to a device or emulator.
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.
How to launch the external android app from the ionic application.
I want to connect POS printer to my app for printing bill.
Cordova-npm plugin for printer can't work that printer. so i install POS printer android application on my tablet so only i want to integrate the ionic app and pos printing app
Install: cordova plugin add com.lampa.startapp
Install: cordova plugin add https://github.com/lampaa/com.lampa.startapp.git
finally in ionic to call the external installed app:
$scope.printer = function () {
navigator.startApp.start("com.example.possdkforandroid", function (message) {
/* success */
alert(" navigator called");
alert(message);
},
function (error) { /* error */
console.log(error);
alert(error);
});
}
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);
});
}