I want to use this cordova plugin at https://github.com/katzer/cordova-plugin-local-notifications
How to go about integrating this plugin with my existing IBM Worklight project? I have trying various methods to integrate it without any result.
I am getting this error currently from the logcat:
02-24 11:15:03.035: D/CordovaLog(2439): file:///data/data/com.iCareApp/files/www/default/index.html: Line 17 : Uncaught TypeError: Cannot read property 'notification' of undefined
Or is there any other easier alternatives to get this done? Basically i want to be able to schedule local notification on the device at specific times from the data stored in my application
I got this to work by following the below.
Demo project: https://www.dropbox.com/s/58urdluauc8u3l1/AndroidLocalNotifications.zip
Because Worklight does not support Cordova's Plugman to easily "install" Cordova v3 plug-ins, some manual labor is required to get it all set-up properly... blachs.
Note the appName , it is used throughout the process for plug-in declarations. If you use a different name for in your app, you will need to update the values accordingly with yours.
Pay attention to the nativeResources folder, where I've placed the files I edited:
AndroidManifest.xml:
In it I added the required permission, receivers, activities
libs folder:
Contains required .jar file by the plug-in
src folder:
Contains the plug-in's Java classes
In them I've edited the plug-in import declaration
res\xml folder:
Contains config.xml; see at the bottom for the plug-in feature declaration
In index.html:
The plug-in's JavaScript implementation is referenced in the head element
<script src="js/local-notification.js"></script>
In main.js:
function wlCommonInit(){
window.plugin.notification.local.add({ message: 'this is a local notification' });
}
The above will send a local notification immediately after the application's launch.
In the plug-in's homepage you can read more about the possible notification options.
In local-notification.js:
Add at the top:
cordova.define("LocalNotification", function(require, exports, module) {
Add at the bottom:
});
In the generated Android project\assets\www\default\js\worklight\cordova_plugins.js, add:
,
{
"file": "../js/local-notification.js",
"id": "LocalNotification",
"clobbers": [
"plugin.notification.local"
]
}
Note that re-building the Worklight project will overwrite this file, and thus your changes in it will be gone... you'll need to repeat this step after every build.
There is no good way that I could find to preserve changes to this file between Worklight Studio builds.
Related
I have a NativeScript/Angular application that uses code sharing.
To make my project more organized, I have created a core folder that contains a sub-folder for routing:
Routes are defined in app.common.ts:
export const appRoutes: Routes = [
{ path: '', redirectTo: '/products', pathMatch: 'full' },
{
path: 'products',
loadChildren: '../products/products.module#ProductsModule'
}
]
Of particular interest is the module path shown in the following property:
loadChildren: '../products/products.module#ProductsModule'
Serving this in the browser using ng serve -o works fine.
Bundling this to run on Android using tns run android --bundle doesn't work as it can't find the module.
If I change the path to ~/app/products/products.module#ProductsModule, the Android app then runs, but the web application can't find the module.
If I then leave the file watcher running for the Android build and change the path back to ../products/products.module#ProductsModule, both Android and web work fine.
I don't want to move my routing files back to the src folder. I am also reluctant to include any hacks such as platform-driven path string mangling.
If you have any explanations as to why this is happening and/or a robust fix that isn't 'hacky', I'd be keen to hear it.
The problem was stemming from some quirks regarding the file watchers. When I change the path to the following, both platforms work fine:
../../products/products.module#ProductsModule
The reason I didn't select this path from the outset is because I used ~/app/products/products.module#ProductsModule to begin with and edited this to get the web build to work while the Android file watcher was still running.
With both the Android and web file watchers terminated and the path adjusted to the one provided above, they both work.
I am learning to use cordova and i have been just doing a normal install of android platform in my cordova application, everything worked fine except for some errors i don't intent to fix just yet (which are external resource files loaded from javascript). I just installed phonegap-plugin-push for working on a push notification support, i believe i have to first register the device on which the notification should be recieved so i ran the app without any other configuration rather than downloading the libraries and putting the google-services.json file at the root application folder.
I try to find the commands for pushing but i am unabled to do so and i think it might be because of an error thrown in the console
Failed to load resource: net::ERR_FILE_NOT_FOUND /cordova_plugins.js
so i have been searching on google and i have found that i don't need to add anything but cordova.js as i have already done upon cordova application installation in order to work with cordova features.
I don't know if i have to add something else or if i am missing some code in order to make this plugin work, probably this plugin is not compatible with cordova but phonegap is built over cordova so i don't know.
in case it is necessary, this are the versions i am using:
Cordova-CLI: 7.1.0
Google Play Services: 46
Android support repository: 47
Android SDK: 26
I failed to say that the application running in cordova is done with angular and angular-ui-router.
After long hours of testing i've found out that the problem is caused by angular-ui-router, because i was using angular-ui-router i have set a <base href> tag in the head tag which is what is making cordova to fail, this is now actually how cordova is intended to work, it is because of how the files are placed. On android the files are placed in android_asset/www/, i don't know how the files are placed in other platforms, but when <base href> tag is set with a new value then the calls are now trying to be done in a directory where the files are not placed.
The solution in angular is to not set a <base href> tag and disable html5Mode in the config
app.config(["$stateProvider", "$locationProvider", "$urlRouterProvider",
function($stateProvider, $locationProvider, $urlRouterProvider){
// Set the default url state
// NOTE: Do not set <base href> tag, this breaks cordova calls
$urlRouterProvider.otherwise("/");
// Disable html5 native router mode
$locationProvider.html5Mode(false);
......
}
]);
I've realized this because in chrome device remote inspector i was getting error calls to wrong directories, by looking at the url where the application is running i saw that the calls were not in the proper directory
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'm porting a Phonegap 2.7 application to Phonegap 3. The application is hosted, so phonegap loads an external url instead of a local html. This hosted webapp loads cordoba.js, however I'm unable to use plugins such as splashscreen and notifications from the hosted webapp:
navigator.splashscreen.hide();
// Uncaught TypeError: Cannot call method 'hide' of undefined
navigator.notification.vibrate(500);
// Uncaught TypeError: Cannot call method 'vibrate' of undefined
The hosted application required the same Cordova file that was included when I created the Phonegap 3 project. Why am I unable to use this API's? This worked fine on Phonegap 2.7.
UPDATE: Events are triggered correctly:
document.addEventListener('deviceready', callback, false);
callback is correctly called, so there is some kind of cordova interaction already. Problem seems plugins.
Call the plugin directly with cordova.exec. it goes like this:
cordova.exec(function(response){}, function(errorText){}, "PluginName", "method", []) ;
Cordova exec()!
I wonder if your cordova.js file just doesn't have the navigator.splashscreen object. In Cordova 3.0, all of the plugins were separated out, and the cordova.js file just became the bridge code. When the app runs, it loads all of the plugin .js files via ajax - see the cordova_plugins.js file in a built project. As it loads these files, Cordova will fix up the namespaces for you, so that navigator.splashscreen namespace actually maps to the splashscreen js code. I'm betting you are not loading this cordova_plugins.js file which means the clobbering isn't working.
It's still working because the bridge code works. When you use exec() you're just running the command that navigator.splashscreen.hide does: https://github.com/apache/cordova-plugin-splashscreen/blob/master/www/splashscreen.js#L26
If I were you, I'd try to rebuild the app the new Cordova 3.x way, with the cordova cli. That way you won't have to actually call the exec function manually which seems pretty brittle (the exec() probably won't change, but it seems like a pain looking up the exec calls for every plugin interaction you need.)
BTW I'm not sergio on irc, so feel free to give him the answer if he posts since he answered your question first. I'm just trying to explain why that happens and why it doens't work for you anymore - basically, 2.7 and 3.x are pretty different in terms of plugins.
I want use dojo in phonegap application.I tried test applications of dojo in android.But they are not displaying anything in emulator.Can anyone help me how to use dojo in phonegap application.
thanks
Himabindu
Android has some problems with the dynamic loading. This means you have to make a custom-build of dojo 1.7.1.
To make a custom build you need the src version of dojo.
I extended the profile file "baseplus.profile.js" found in the directory "dojo/util/builsscripts/profiles/" as follows:
dependencies = {
selectorEngine: "acme",
layers: [
{
// This is a specially named layer, literally 'dojo.js'
// adding dependencies to this layer will include the modules
// in addition to the standard dojo.js base APIs.
name: "dojo.js",
dependencies: [
"dijit._Widget",
"dijit._Templated",
"dojo.fx",
"dojo.NodeList-fx",
//this wasn't included in the standard build but necessary
"dojo._firebug.firebug",
//my used dojo requirements
"dojox.mobile.parser",
"dojox.mobile",
"dojox.mobile.Button",
"dojox.mobile.SwapView",
"dojox.mobile.ScrollableView",
"dojox.mobile.TabBar",
"dojox.mobile.SpinWheelTimePicker",
"dojox.mobile.compat"
]
}
],
prefixes: [
["dijit", "../dijit" ],
["dojox", "../dojox" ]
]
}
you have to execute the build.sh (Unix/OSx) or build.bat (Windows) in the shell with the command "./build.sh action=release profile=profiles/myBaseplus.profile.js -r"
After a successful build you find the dojo.js file in "dojo/release/djojo/dojo.js".
You only need this file.
Never the less you will also need the following require statement in your html file:
require([
"dojox/mobile/parser", // (Optional) This mobile app uses declarative programming with fast mobile parser
"dojox/mobile", // (Required) This is a mobile app.
"dojox/mobile/Button",
"dojox/mobile/SwapView",
"dojox/mobile/ScrollableView",
"dojox/mobile/TabBar",
"dojox/mobile/SpinWheelTimePicker",
"dojox/mobile/compat" // (Optional) This mobile app supports running on desktop browsers
],
function(parser, mobile, compat){
//Optional module aliases that can then be referenced inside callback block
}
);
Try renaming tweetview.html to index.html.
The PhoneGap entry point file name needs to match the file name from the native source. On Android the connection comes from src/{com.package}/{activityname}.java.
super.loadUrl("file:///android_asset/www/index.html");