I am using Ionic 3 and my device is 4.4.2 android.
Setup:
ionic cordova plugin add cordova-sms-plugin
npm install --save #ionic-native/sms#4
I have add to app.module
import { SMS } from '#ionic-native/sms';
providers: [..., SMS]
home.ts
...
import { SMS } from '#ionic-native/sms';
...
constructor(..., private sms: SMS){}
sendSMS(){
this.sms.send('0030699999999', 'sos')
}
home.html
<button ion-button block (click)="sendSMS()" margin-top color="dark">SMS</button>
I install the apk to my phone with below command:
ionic cordova run android
When I am pressing the button, my app breaks and exit, without sending a message.
I tried to remove platform android and added again, but nothing.
Allow from app settings on your phone
I had to put a send_sms permission in manifest file (android).
Check in my phone v 4.4.2.
I didn't check it in iPhone.
Related
I have a Vue2 App, when i try to use vue-cordova-cli on mine app for deploy on android's device, it doesn't works and only look a with blank screen, i look for all sites of internet for look the solution with not luck.
I display you the configuration that i have:
System Operative: Windows 10
CLI: Powershell (Administrative Privilege)
Android: 7.1.1
Commands npm
vue add cordova
npm run cordova-prepare
npm run cordova-serve-android
main.js
import Vue from 'vue'
import App from './App.vue'
Vue.config.productionTip = false
new Vue({
render: h => h(App),
}).$mount('#app')
vue.config.js
module.exports = {
publicPath: '',
pluginOptions: {
cordovaPath: 'src-cordova'
}
}
More info: All my test are doing using my device connect to my pc using a usb link and i have a lot of deploy previously to that using that way.
When using the NFC library the Ionic docs recommend
(https://github.com/chariotsolutions/phonegap-nfc)
(https://ionicframework.com/docs/native/nfc) I get a ''plugin not installed'' error when trying to reach the code in my component calling the ndef or nfc providers on my Android One Plus through the 'ionic serve --devapp' CLI command. It also says the devapp does not support this plugin, but I am unclear about how I am supposed to go about using this package testing wise in that case.
After specifying version 4 as per suggestion of this post for Ionic 3 I got a different error. This is with rxjs-compat installed and none of the nfc/ndef code actually used aside the imports in the module and component, and the injection into the constructor.
This is using "import {Ndef, NFC} from '#ionic-native/nfc';" instead of /nfc/ngx like above.
Uncaught TypeError: Object(...) is not a function
at index.js:405
at Module../node_modules/#ionic-native/nfc/index.js (index.js:599)
at __webpack_require__ (bootstrap:84)
at Module../src/app/app.module.ts (app.component.ts:12)
at __webpack_require__ (bootstrap:84)
at Module../src/main.ts (main.ts:1)
at __webpack_require__ (bootstrap:84)
at Object.0 (main.ts:12)
at __webpack_require__ (bootstrap:84)
at checkDeferredModules (bootstrap:45)
When I try to build the app instead of serving it with the devapp I come across this (perhaps unrelated) error, even though I am running the app in Android Studio on Windows 10 and have both my Java, Android and Gradle paths defined in my environment variables.
ANDROID_HOME=C:\Users\Sam\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_181
Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
I have added the imports and the provider in the app module.
import {Ndef, NFC} from '#ionic-native/nfc';
#NgModule({
...
providers: [
NFC,
Ndef,
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
This is how I inject the providers into my class.
import { Component } from '#angular/core';
import {ToastController} from '#ionic/angular';
import {Ndef, NFC} from '#ionic-native/nfc';
#Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor(private nfc: NFC, private ndef: Ndef, private toast: ToastController) {
}
Maybe I am completely on the wrong path about this, but following the documentation or any of the suggestion threads available on similar topics have not lead anywhere. Am I approaching this wrong?
EDIT: After running everything in a new project and making sure I go through each and every step without making any errors, I again end up with the INSTALL PLUGIN ERROR, like such.
[ng] [console.warn]: "Install the NFC plugin: 'ionic cordova plugin add phonegap-nfc'"
[ng] [console.warn]: "Native: tried calling NFC.removeNdefListener, but the NFC plugin is not installed."
[ng] [console.warn]: "Install the NFC plugin: 'ionic cordova plugin add phonegap-nfc'"
[ng] [console.log]: "Angular is running in the development mode. Call enableProdMode() to enable the production mode."
[ng] [console.log]: "calling _sync"
[ng] [console.error]: "ERROR" "plugin_not_installed"
[ng] [console.info]: "[WDS] Live Reloading enabled."
[ng] [console.log]: "calling _reload"
[ng] [console.log]: "done _reloading"
[ng] [console.log]: "Ionic Native: deviceready event fired after 836 ms"
This error appears in my console only when I open up the Android version of the app in DevApp after serving it with serve --devapp. It does not appear when I run it in the browser, it then just gives me the ''Cordova'' not available error, which I imagine is standard for plugins that don't work on certain devices. This is done following the exact step by step process, including the code in the ionic docs. https://ionicframework.com/docs/native/nfc
EDIT2: It might have to do with an XML processing error. When running through the same steps as before I came across an error I dismissed earlier when installing the plugin due to it resolving itself after installing both the iOS and Android platforms on Cordova. The error below happens after running the 'ionic cordova plugin add phonegap-nfc' command. The plugin however DOES install, and is listed under 'cordova plugin list' afterwards, but the installation might not be done completely correctly. The plug-in is not listed under the plugins in config.xml for example.
Failed to install 'phonegap-nfc': Error: Unable to graft xml at selector "/manifest/uses-sdk" from "C:\Users\cliem\Desktop\dev\nfctest\nfctest2\platforms\android\app\src\main\AndroidManifest.xml" during config install
at ConfigFile_graft_child [as graft_child] (C:\Users\cliem\Desktop\dev\nfctest\nfctest2\node_modules\cordova-common\src\ConfigChanges\ConfigFile.js:122:19)
Long story short, don't use a Java version over 8. Nfc plugin does not work with ionic serve --devapp and needs to be tested with ionic cordova run android instead. Console needs to be read out from chrome://inspect.
If you have the latest version of cordova which is 9.0.0, try
$ sudo npm uninstall -g cordova to uninstall it and install in back again with a previous version
$ sudo npm uninstall -g cordova#8.x
This worked for me
I have an Ionic project and I installed this plugin to scan qrcodes:
cordova plugin add https://github.com/wildabeast/BarcodeScanner.git
But when I run the app on a samsung s5 device with Android 6.0 I get a camera error:
"Sorry, the Android camera encountered a problem. You may need to restart the device"
Any ideas of what causes this issue?
I have tested with:
ionic run android -l -c
ionic run android
This is my code executed when I press a button:
$scope.scanBarcode = function() {
$ionicPlatform.ready(function() {
$cordovaBarcodeScanner.scan().then(function(imageData) {
console.log("Barcode text -> " + imageData.text);
console.log("Barcode Format -> " + imageData.format);
console.log("Cancelled -> " + imageData.cancelled); // prints: cancelled
}, function(error) {
console.log("An error happened -> " + error);
});
});
};
For this issue you can try either of below solutions:
1) It is permission issue with android 6. So to fix the issue configure platform to android 5.0.
OR if you are using MI note 4 you can try below additional steps:
There is another permission required in MIUI secruity system and after enabling it, camera started working.
Following are the steps you can follow to update the setting:
1) Go to Security.
2) Click on “Permissions” and again select “Permissions”
3) Now from the list, click on “Camera”.
4) It will list all the apps installed. Look for your app and enable the permission.
Reff: http://sforsuresh.in/cordova-sorry-android-camera-encountered-problem/
This is what solved my problema, in the config.xml file in the "android" platform section I put:
<platform name="android">
<preference name="android-targetSdkVersion" value="22"/>
</platform>
I've written a small application to test the working of cordova app on XDK.
The source code is same as this question
However, I am attaching the code here :
(function()
{
"use strict";
/*
hook up event handlers
*/
function register_event_handlers()
{
/* button Login */
$(document).on("click", ".uib_w_9", function(evt)
{
//intel.xdk.notification.showBusyIndicator();
/*$.post("http://url/test.php", {test:'1'},
function(res){
alert(res);
}
);*/
$.ajax({
beforeSend: function(){
intel.xdk.notification.showBusyIndicator();
},
type: "GET",
url: 'http://url/test.php',
data:{test:'1'},
success: function(res){
alert(res);
intel.xdk.notification.hideBusyIndicator();
},
error:function(res){
alert(res);
intel.xdk.notification.hideBusyIndicator();
},
dataType: 'text'
});
});
}
document.addEventListener("app.Ready", register_event_handlers, false);
})();
This is the JS file of the application.
The screenshot of the app in XDK emulator :
Now When I do a build of the app using XDK cloud, I get a .apk file.
On uploading the file to GenyMotion Emulator, screen below :
The click doesn't do anything, nor does the showBusyIndicator() show, nor the alert appear.
What am I missing and what is going wrong ?
I've plans to use this ide for a proper project and hence the testing, some help will be appreciated.
UPDATE
I did a Cordova Hybrid App build initially and that caused the problem.
When I did a legacy android build, then the problem was solved.
So what do I need to do to get it to work with the Cordova Build ?
Build Page :
There is a known issue with AJAX when Intel XDK builds apk with Cordova CLI version 4.1.2. on Android version > 4.4
There is a workaround, go to Project Settings -> Build Settings -> Android, change Cordova CLI version from 4.1.2 to 3.5 and AJAX should work.
I'm completely new to phonegap. I started with phonegap build - by running 'npm install -g phonegap'.
My system is windows7.
When i run the command 'phonegap run android' i'm getting console messages as follows:
[phonegap] detecting Android SDK environment..
[phonegap] using the local environment
[phonegap] compiling Android...
[phonegap] successfully compiled Android app
[phonegap] trying to install app onto device
[phonegap] successfully installed onto device
I can see the app running on my device (sony Xperia -E).
But when i put in my javascript code:
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
console.log('Received Event: ' + id);
//HERE
alert(navigator.camera)
}
i keep getting alert which say 'undefined'. I checked the same with navigtaor.geolocation, and it wasnt undefined.
I guess it something to do with camera plugin. Am i right?
Please Help
Thanks Forwards
You have to add these things:
--> app/res/xml/plugins.xml
<plugin name="Camera" value="org.apache.cordova.CameraLauncher" />
--> app/AndroidManifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
After looking itno this project i figured out where was my mistake
I tried to use the 'ondeviceready' eventhandler which comes with index.js.
Dont know why yet, but this handler fires when camera is undefined.
After i specified my own handler on the page
document.addEventListener("deviceready",onDeviceReady,false);
function onDeviceReady() {
alert(navigator.camera);
}
camera became defined
It is supposed to have the cordova-plugin-camera plugin added to your PhoneGap/Cordova project, so just this way you'll get the example working.
See the right command:
cordova plugin add cordova-plugin-camera
Before running phonegap application, make sure you add the lib:
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture.git
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-media.git
If you omit loading the plugin before building the app it will not work, I also had problems sometimes with installed plugins, so if you did install them, try removing and re-adding them, that worked for me. You can check what plugins are installed by:
phonegap local plugin list
For more information please visit: Official Phonegap Documenattion
Regarding: navigtaor.geolocation it is a standard HTML5 call so if the geolocation plugin is not installed (at least on Android) it will be interpreted as a standard HTML5 geolocation call.
This worked for me, I guess someone needs to make a release.
cordova plugin remove cordova-plugin-camera && cordova plugin add https://github.com/apache/cordova-plugin-camera