Wednesday, September 11, 2013

PhoneGap Android AndroidPreferences Plugin

Update: Changed to be compatible with PhoneGap 3 and higher.

Here is a small blog about how to store preferences of your PhoneGap app on the native side, using SharedPreferences.

What does it do


This plugin can be very handy if you are having multiple services that run native code, but need to use shared preferences. You can set, get and compare values. No further coding in Java is required, as it works out of the box. Every value is stored as a string (so no booleans, integers or any other type than strings).

PhoneGap plugin


The above is done by creating a phonegap plugin. Create the class (.java file) in the package "org.apache.cordova.plugins"

AndroidPreferences.java



Create the javascript file "androidpreferences.js" and include it in your HTML AFTER the include of the phonegap/cordova javascript files.

androidpreferences.js



Add the following line to the "config.xml" file in your res folder of your Android project.

And from that point you can call the plugin in your application by using the statement below.

In your app (javascript)



The  script above can be adjusted to your liking of course.

If you have questions please let me know.

Copyright (c) 2015 Joram Teusink

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Sunday, August 11, 2013

PhoneGap Android Appstore Plugin

Update: Changed to be compatible with PhoneGap 3 and higher.

Here is a small blog about how to send an intent to start Google Play Store app or website (depending if the store is installed) with a specific link.

What does it do


It sends a command to the plugin to initiate an intent on Android to either execute a link or start the Play Store.

PhoneGap plugin


The above is done by creating a phonegap plugin. Create the class (.java file) in the package "org.apache.cordova.plugins"

Appstore.java



Create the javascript file "appstore.js" and include it in your HTML AFTER the include of the phonegap/cordova javascript files.

appstore.js



Add the following line to the "config.xml" file in your res folder of your Android project.

And from that point you can call the plugin in your application by using the statement below.

In your app (javascript)


The  script above can be adjusted to your liking of course.

If you have questions please let me know.

Copyright (c) 2015 Joram Teusink

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Saturday, July 20, 2013

PhoneGap Android CacheCleaner Plugin

Update: Changed to be compatible with PhoneGap 3 and higher.

Here is a small blog about how to clear the cache of a PhoneGap app on the Android platform.

What does it do


It sends a command to the plugin to initiate the cache clean in Android.

PhoneGap plugin


The above is done by creating a phonegap plugin. Create the class (.java file) in the package "org.apache.cordova.plugins"

CacheCleaner.java



Create the javascript file "cachecleaner.js" and include it in your HTML AFTER the include of the phonegap/cordova javascript files.

cachecleaner.js



Add the following line to the "config.xml" file in your res folder of your Android project.

And from that point you can call the plugin in your application by using the statement below.

In your app (javascript)


The  script above can be adjusted to your liking of course.

If you have questions please let me know.

Copyright (c) 2015 Joram Teusink

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

A guide to PhoneGap 3 development for Android on Windows.

This is a guide to start developing with PhoneGap 3 for Android on a Windows machine. It has everything included, but only the basics. See the supplied URLs for more information. If you have any questions, enhancements, comments or complaints, please feel free to let me know.

Important message: I do not know the impact of the dropped support by Google of the Eclipse tools for developing for Android with PhoneGap. I do not have any plans at the moment to check if Android Studio can be used in combination with PhoneGap.

Overview, what you need

You need the following platforms / software packages:
  • Java JDK 6 or 7
  • Android SDK tools
  • Integrated Development Environment (IDE): Eclipse and Eclipse Plugin
  • Apache Ant
  • GitHub
  • Node.js
  • Cordova PhoneGap
Skip the parts below if you already have installed / configured them.

Install the tools

Java JDK 6 or 7


Make sure you download the JDK. Eclipse can build against Java 6 with Java 7, so it is fine to have only 7 on board. Officially, Android supports only Java 6, so it is not possible to compile/build against Java 7.

Just install the download as you go (next, next... finish). Make sure that you make you have the following set in your advanced system properties, environment variables.

System variables:
  • JAVA_HOME: C:\Program Files\Java\jdk1.7.0_25
    • The "1.7.0_25" part might be different, depending on which version you are installing.
  • Path: %JAVA_HOME%\bin
    • Add the line above at the end of the rest of the paths and make sure it precedes with an ;

Android SDK tools


Download the SDK (adt-bundle) from the link above and extract it to a folder you like. In this case: "D:\AndroidDev\android-sdk\". Make sure that you make you have the following set in your advanced system properties, environment variables.

System variables:
  • Path: D:\AndroidDev\android-sdk\platform-tools;D:\AndroidDev\android-sdk\tools
    • Add the line above at the end of the rest of the paths and make sure it precedes with an ;
Start the SDK manager and download the API levels you need (I did Gingerbread, Ice Cream Sandwich and Jelly Bean versions).

Eclipse and Eclipse Plugin


Eclipse is integrated in the download from the SDK tools. Extract the contents (eclipse) in this case to D:\AndroidDev\eclipse\

When you start Eclipse add the plugins like it is described in the link above. When Eclipse asks for the Android SDK, select folder "D:\AndroidDev\android-sdk\".

User variables:
  • HOME:  %USERPROFILE%

Android Studio


Important note: As of this moment it is not possible to build PhoneGap apps with Android Studio.

Apache Ant


Download the file and extract it to (in this case): "D:\AndroidDev\apache-ant"

Make sure that you make you have the following set in your advanced system properties, environment variables.

System variables:
  • ANT_HOME: D:\AndroidDev\apache-ant
  • Path: %ANT_HOME%\bin
    • Add the line above at the end of the rest of the paths and make sure it precedes with an ;

GitHub


Download and install GitHub. Start GitHub and configure anything if needed.

Node.js


Download the installer from the link above and install it the standard way (next, next.... finish).

It will automatically add it self to the path variables. For reference they are mentioned below here anyway.

User variables:
  • Path: C:\Users\Joram\AppData\Roaming\npm
    • Where as Joram is my username and should be yours.
System variables:
  • Path: C:\Program Files\nodejs\

Cordova PhoneGap

PhoneGap information (install): https://github.com/mwbrooks/phonegap-cli

You can now download PhoneGap using the Command Line Interface (CLI). Using this method you can select which platform you need, which plugins you need and then build the sources.

The commands below are done with cordova, in stead of phonegap. It is possible to them with phonegap also. Personally, I advice to use the phonegap version, in stead of cordova. Somehow using cordova the needed files are not generated properly.

Difference between Cordova CLI and PhoneGap CLI, according to the FAQ

The PhoneGap CLI is built on top of the Cordova CLI. It has all of the functionality that the Cordova CLI has. The main difference is that the PhoneGap CLI has PhoneGap Build integration. So if you don’t have the native SDK installed, you can delegate compilation to the PhoneGap Build cloud service and get app-store ready mobile apps. Both tools are completely interoperable.
The steps (execute either the Cordova or PhoneGap command, not both), for reference I list them both:
  • Download Cordova or PhoneGap, open Command Prompt (cmd), and type the command below.
    • npm install -g cordova
    • npm install -g phonegap

Create App

Create project

  • In Command Prompt (cmd) go to the folder in which you maintain your source code and type the command below. This will create a HelloWorld app (change the name if needed).
    • cordova create HelloWorld com.example.hello "Hello World"
    • phonegap create D:\HelloWorld
    • cd HelloWorld
  • Then add the Android platform with the following command in the Command Prompt (cmd).
    • cordova platform add android
    • <not needed for PhoneGap as far as I know.>
  • Want to remove the Android platform? Highly doubt that, but you'll never know.
    • cordova platform remove android

Install plugins

  • If you need any plugins (be specific!) execute the following commands in Git Shell (installed with GitHub)
    • Commands in CLI:
      • cordova plugin add <git-url>
      • phonegap local plugin add <git-url>
      • Replace <git-url> with the addresses here below (replace also the < and >)
    • Basic device information:
      • device: https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git
    • Network and battery status:
      • network-information: https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git
      • battery-status: https://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status.git
    • Accelerometer, compass, and geolocation:
      • device-motion: https://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion.git
      • device-orientation: https://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation.git
      • geolocation: https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
    • Camera, media capture, and media playback:
      • camera: https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git
      • media-capture: https://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture.git
      • media: https://git-wip-us.apache.org/repos/asf/cordova-plugin-media.git
    • Access files on device or network:
      • file: https://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git
      • file-transfer: https://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer.git
    • Notifications via dialog box or vibration:
      • dialogs: https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git
      • vibration: https://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration.git
    • Contacts:
      • contacts: https://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts.git
    • Globalization:
      • globalization: https://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization.git
    • Splash Screen:
      • splashscreen: https://git-wip-us.apache.org/repos/asf/cordova-plugin-splashscreen.git
    • In-app browser:
      • inappbrowser: https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git
    • Debug console:
      • console: https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git
    • Dialogs:
      • dialogs: https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git
  • If you want to see which plugins have been added, execute the following commands.
    • cordova plugin list
    • phonegap local plugin list

Removing plugins

  • If you need to remove any plugins (be specific!) execute the following commands in Git Shell (installed with GitHub)
    • Commands in CLI:
      • cordova plugin remove org.apache.cordova.<plugin name>
      • phonegap local plugin remove org.apache.cordova.<plugin name>
      • Replace <plugin name> with a name above (replace also the < and >)

Build and compile the app

  • Make the build with the following command (in Command Prompt).
    • cordova build android (it does a prepare and compile command in one)
    • phonegap local build android
  • Then you can run it (or add it to Eclipse or Android Studio).
    • cordova emulate android
    • phonegap local run android
All the sources should be ready now and you can start using PhoneGap and building your app.

Debug Console

More information about debugging webapps on Android: https://developer.android.com/guide/webapps/debugging.html

Send information to the console

In your JavaScript use one of the following commands below.
  • console.log(String)
  • console.info(String)
  • console.warn(String)
  • console.error(String)

Debug console

  • To see the logcat in a Command Prompt (cmd), execute the following command.
    • adb logcat
  • If you want to have (way) more options, make use of eclipse. Execute the following command.
    • monitor

Debugging through Chrome

You can also debug your PhoneGap application through the Chrome Developer tools. This also includes live editing of code and see instant results of that. Much easier tweaking and improving your code!

Use this example below to adjust your project to support Chrome remote debugging.

Updating

Cordova PhoneGap


Updating to a newer PhoneGap version is done in a couple of steps. See below. Also in this part, for the moment, go for the phonegap-cli commands.
  • Check your current version
    • cordova -v
    • phonegap -v
  • Update Cordova or PhoneGap, open Command Prompt (cmd), and type the command below.
    • npm update -g cordova
    • npm update -g phonegap

Update your project

Create new project...

  • Create a new project.
  • Add all the necessary plugins.
  • Add your assets content (HTML, CSS, JavaScript and other files, basically your entire web-app).
  • Make the new build with the following command.
    • cordova build android (it does a prepare and compile command in one)
    • phonegap local build android
  • Then you can run it (or add it to Eclipse or Android Studio).
    • cordova emulate android
  • cordova emulate android
    • phonegap local run android

Update current project...

  • cordova platform update android
  • phonegap platform update android

Easy CLI commands for PhoneGap and Cordova


More...

End-word

I have to say, it is not as easy as PhoneGap 2.9.0 and below, but perhaps the speed of your app increases by this way. The supplied documentation with PhoneGap is, in my honest opinion, bit too short to get you started quickly. I have spent two and a half hours just to go through all the steps (reading, tools and configuration) and make a HelloWorld app. Once you know the drill it is not difficult though.

Sources

Other informational sources and blogs about PhoneGap 3 installment and CLI
Thank you for reading my blog!

Friday, May 3, 2013

Execute code in PhoneGap after DeviceReady event

In same cases you want to execute code in your web-app on the start of your app, but you need to be sure that PhoneGap is loaded. I bumped in to this problem more then once and I found a solution for it.

The code, load it after PhoneGap and before, if it applies, jQuery Mobile. For the script below only PhoneGap is required.


Copyright (c) 2015 Joram Teusink

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Backup and restore webSQL database with PhoneGap and jQuery

This is a blog about some code I made to backup data from a webSQL data to a local file on your device (Android, iOS or some other, whatever supported by PhoneGap).

It reads the database and writes the content to a text file in JSON format. Restore is obviously the other way around.

Tested on:
- PhoneGap 2.5.0
- jQuery 1.9.1

All the Javascript code can be in a single file (in example: backuprestore.js). It has to be loaded AFTER PhoneGap and AFTER jQuery. Change it to your liking or needs.

It can also be used in addition to jQuery Mobile, but it is not needed.


Copyright (c) 2015 Joram Teusink

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Monday, April 29, 2013

Android example app with PhoneGap and JQM in Holo style

In this blog I will write about how to make a app with PhoneGap and jQuery Mobile and a custom theme to have the looks of (almost) a native Android app. Including the Toast and Share plugin I wrote about earlier.

I have made a complete download package of the Android project (including activity class, manifest file, html, javascript, css and images). You can import this package in Eclipse and run the example app right away or adjust it to your liking first.

I have added comments in the code to explain what it does.

This app is the base code of my own app called DroidPapers.

Updated 22 may 2013

- PhoneGap 2.7.0
- Improved JavaScript code with JSLint
- Changed panel behavior to the official Google style presented at Google I/O 2013.

Updated 23 may 2013

- Changed app to remove the blink issue (meta viewport). App now functions without blinking.

Updated 29 juni 2013

- Added tablet view support.
- Improved Holo colors.
- Added to GitHub public repo now (click here).
- All future updates can be found on GitHub.

Goal

My goal with this example app is to have some sort of a template to make a new app very fast, based on the technologies supplied by PhoneGap and jQuery Mobile, using web-technology.

Details

Frameworks:
  • Suitable for Android 2.3.3 and higher. API level 10 and up to be more technical :).
  • PhoneGap 2.7.0.
  • jQuery 1.9.1
  • jQuery Mobile 1.3.1
Features in this example app:
  • Holo theme. Dark, light with dark header and light with light header. The last one isn't very worked out yet, but it should give you a heads up start. The header features the same style as a native app including press effects.
  • Panel menu like the Google Plus app. Tap on title to open and tap outside panel menu to close. You can also swipe to left to close. Upon first boot the panel menu opens and closes for a brief second automatically, to demonstrate where the menu is. Panel menu content is defined only once, in the javascript.
  • Of course the use of the plugins Share and Toast.
  • Native Android like back-button behavior.
  • Supplied Gimp image files (xcf files) to easy edit the icons to your liking.
Notice: The Holo theme is almost like and very inspired by Holo for Android. It is not exactly the same for 100% as native.

Check out this example web-app of jpHolo through a website.

Screenshots of the interface




Additional info about the platforms

Download

Check my GitHub here for the source code. If you have any questions, please let me know!

Thank you for reading my blog!


Copyright (c) 2015 Joram Teusink

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Thursday, April 18, 2013

PhoneGap Android Share Plugin

Update: Changed to be compatible with PhoneGap 3 and higher.

Here is a small blog about how to share text in a PhoneGap app on the Android platform. It is based on the plugin on github (link), but that plugin is slightly out-dated PhoneGap wise.

What does it do


It sends a subject and  a text (strings) to the plugin to initiate a share action in Android.

PhoneGap plugin


The above is done by creating a phonegap plugin. Create the class (.java file) in the package "org.apache.cordova.plugins"

Share.java



Create the javascript file "share.js" and include it in your HTML AFTER the include of the phonegap/cordova javascript files.

share.js



Add the following line to the "config.xml" file in your res folder of your Android project.

And from that point you can call the plugin in your application by using the statement below.

In your app (javascript)



The  script above can be adjusted to your liking of course.

If you have questions please let me know.


Copyright (c) 2015 Joram Teusink

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

PhoneGap Android Toast Plugin

Update: Changed to be compatible with PhoneGap 3 and higher.

Here is a small blog about how to display a toast message in a PhoneGap app on the Android platform.

It is based on the plugin on github (link), but that plugin is slightly out-dated PhoneGap wise.

What does it do


It sends a text (string) with an option (long or short) to the plugin to display an Android toast message.

PhoneGap plugin


The above is done by creating a phonegap plugin.

Create the class (.java file) in the package "org.apache.cordova.plugins"

Toasts.java



Create the javascript file "toasts.js" and include it in your HTML AFTER the include of the phonegap/cordova javascript files.

toasts.js



Add the following line to the "config.xml" file in your res folder of your Android project.

And from that point you can call the plugin in your application by using the statement below.

In your app (javascript)


The  script above can be adjusted to your liking of course.

If you have questions please let me know.


Copyright (c) 2015 Joram Teusink

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

PhoneGap Android Downloader Plugin

Update: Changed to be compatible with PhoneGap 3 and higher.

Here is a small blog about how to perform a download with a progress bar in the notification tray in a PhoneGap app on the Android platform.

It is based on the plugin on github (link), but that plugin is slightly out-dated PhoneGap wise.

What does it do


It downloads a file (url) that is send to the plugin.

PhoneGap plugin


The above is done by creating a phonegap plugin.

Create the class (.java file) in the package "org.apache.cordova.plugins"

Downloader.java



Create the javascript file "downloader.js" and include it in your HTML AFTER the include of the phonegap/cordova javascript files.

Important: be sure to change the "import org.teusink.pg_jqmexampleapp.R;" in the code above (change org.teusink to your own packagename).

downloader.js



Add the following line to the "config.xml" file in your res folder of your Android project.

And from that point you can call the plugin in your application by using the statement below.

In your app (javascript)


Notification icons


You can generate your own notification icons in the Android Asset Studio by Roman Nurik, Google (they are free to use under the Creative Commons License).

Important: these icons are used in the code, see ".setSmallIcon(R.drawable.ic_stat_notification)" part. Of course you can skip or change them, but you will have to adjust the Java code.

Support library (jar file)


Be sure to include the library "android-support-v13.jar" from the support tools (\android-sdk\extras\android\support\v13) from the Android SDK in your project (libs folder). This to make sure the notifications work on all platforms of Android 2.3.3 and higher.

The scripts above can be adjusted to your liking of course.

If you have questions please let me know.


Copyright (c) 2015 Joram Teusink

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Sunday, February 10, 2013

PhoneGap Android License Key App Checker Plugin

Update: Changed to be compatible with PhoneGap 3 and higher.

Here is a small blog about how to perform a check in a PhoneGap app on the Android platform to check whether a license key app has been installed or not. This is done by implementing a native Android PhoneGap plugin.

What does it do


It performs a check if two supplied android packages carry the same signature or not and returns true or false. It is not a 100% safe solution, as it is possible to manually install the license key app, but for common use it is pretty much okay.

How to do it


Create the class (CheckKey.java file) in the package "org.apache.cordova.plugins".


Create the javascript file "checkkey.js" and include it in your HTML AFTER the include of the phonegap/cordova javascript files.

checkkey.js



Add the following line to the "config.xml" file in your res folder of your Android project.

And from that point you can call the plugin in your application by using the statement below.

In your app (javascript)



The  script above can be adjusted to your liking of course.

If you have questions please let me know.

Copyright (c) 2015 Joram Teusink

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.