I'm facing a problem when I try to save a contact on Android. It works fine on iOS, but when I try it on Android the app crashes closing itself.
I'm using Ionic 3 and Ionic Native Contacts interface. The plugin is https://github.com/apache/cordova-plugin-contacts. I know it says it's deprecated, but I can't find another trusty plugin.
The troublesome code is the save method:
let contact: Contact = this.contacts.create();
contact.name = new ContactName(null, 'Smith', 'John');
contact.phoneNumbers = [new ContactField('mobile', '6471234567')];
contact.save().then(
() => console.log('Contact saved!', contact),
(error: any) => console.error('Error saving contact.', error)
);
There's a post that has an explanation on this issue, basically you need to replace ContactManager.java file in the contacts plugin that asks for read/write permission, then remove android platform and re add it.
This is the updated ContactManager.java
After updating the file at plugins/cordova-plugin-contacts/src/android/ContactManager.java with the updated version, you have to run:
ionic cordova platform rm android
ionic cordova platform add android
Here is the original post
Related
I am developing an android app based on ionic 2 using typescript.
I would like o open a PDF file inside my app with another app that is registered for the fyletype (e.g. Acrobat Reader).
Therefore i tried the two standard plugins:
https://github.com/disusered/cordova-open
https://github.com/pwlin/cordova-plugin-file-opener2
Although ive added both plugins via "ionic plugin add ..." and of course played around with several combination referencing to it
the result is always that they ere not found
cordova-open
var open = cordova.plugins.disusered.open;
Property 'disusered' does not exist on type 'CordovaPlugins'.
cordova-plugin-file-opener2
cordova.plugins.fileOpener2.open(
filePath,
fileMIMEType,
{
error : function(){ },
success : function(){ }
}
);
Property 'fileOpener2' does not exist on type 'CordovaPlugins'.
I am running the app on an emulator via ionic run android
Could you please give some hint how i can achieve to use one of these plugins?
Thank you very much
Shane
I have added a plugin with Java code (for Android) to my Cordova project. The same java file can now be found under plugins folder and also under the platforms/android folder. Unfortunately when I edit the code in the plugins folder and build the application then the code under the platforms folder is not changed and the emulated app never get updated. Do I have to do something else?
Update
Ok, it seems there is no "automatic" way to update the code in the platforms folder. One has to re-add it. See Cordova 3.5, how to update local plugin? or In Phonegap/Cordova 3.0+, is there any way to refresh plugins after you make changes?
Or does someone know a better way?
This is old but I was searching and this one is without answer. If you have plugin that you've created, you can add directory instead of url. So if you have template on github that need to be modified you need clone it, make changes, and add using:
cordova plugin add /path/to/plugin --nofetch
see docs for cordova cli
I think that you will need to execute this command each time you make changes and before you do you need to remove the plugin:
cordova plugin remove com.example.plugin.name
You can speed things up if you create simple node script that will execute this when file changes:
var watch = require('watch');
var exec = require('child_process').exec;
if (process.argv.length == 4) {
var name = process.argv[2]
var path = process.argv[3];
watch.watchTree(path, function() {
var cmd = 'cordova plugin remove ' + name +
' && cordova plugin add ' + path + ' --nofetch';
console.log(cmd);
exec(cmd, function (error, stdout, stderr) {
if (error !== null) {
console.log('exec error: ' + error);
} else {
console.log('done');
}
});
});
} else {
console.log('usage: ' + process.argv[1] + ' [NAME] [PATH]');
}
then you can save is as plugin.js and run (from your cordova application path):
node plugin.js com.example.plugin.name /path/to/plugin
it will work when you put more then one plugin. Before you run it you need to execute:
npm install -g watch
or:
npm install --save-dev watch
cordova application have package.json file so this dependency will be save there.
I just had/resolved the same issue and found the solution and thought it should be here:
Changes of the java file in the plugin directory won't be updated when building, but editing the one in the platforms/android/app/src/main/java/* will.
you are add plugin using cmd or manually add plugin for your cordova project.
you can directly add plugin using cmd, select your project in directory and direct hit plugin url Example: cordova plugin add nl.x-services.plugins.socialsharing
and automatically add all plugin file, that plugin permissions.
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 have an app which was working fine up until this week, and I've no idea what has suddenly changed.
Consider the following code. The first "console.log" outputs correctly, but NOT ONE of the others outputs anything at all.
console.log('requesting file system');
try {
requestFileSystem(1, 1024*1024, function(fs) {
console.log('file system received. requesting root directory');
fs.root.getDirectory( options.name, {create:true}, function( directory ) {
console.log('root directory received');
filesystems[options.name] = directory;
console.log('calling callback');
if ( callback ) me.fn( me.name, callback ).call( me, me );
console.log('callback called');
}, function(e) {
console.log('error handler 1');
console.log(e);
});
}, function(e) {
console.log('error handler 2');
console.log(e);
});
}
catch(e) {
console.log('error handler 3');
console.log(e);
}
Any ideas what to look for?
I've "solved" this by starting a fresh application, copying the www directory over, re-installing all the plugins from the broken application.
I don't know what problem there was, but this clean installation is working fine now.
This issue lot of them are facing, stems from a bug in cordova nativetoJSbridge.
It has been marked fixed in 3.6.0, but never worked in that version. Couple of versions above the specific version works.
Steps to fix it in your existing project if you are using eclipse.
Install latest cordova using npm and create a new project using CLI.
Add the file api to your new project using cordova plugin add command.
Once the plugin is added to your project, copy the latest java sources of cordova as well as your file api to your old project.
Also, copy the file api plugin javascript sources and diff and merge cordova.js.
Now compiling your old project should fix window.requestFileSystem issue.
If you are using CLI, even better. create a new project from CLI and copy your old project sources to new project and add the plugins using CLI or update your project using CLI.
As a side note, this bug had been around for a while, where the problem seems to be in
NativeToJsMessageQueue
https://issues.apache.org/jira/browse/CB-6761
Though from the bug it reads to be unresolved, it is fixed in latest version above 3.6.x
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