• Noser.com
facebook
linkedin
twitter
youtube
  • NOSERmobile
    • Android
    • HTML 5
    • Hybrid Apps
    • iOS
    • Windows Phone
  • NOSERembedded
    • Medizintechnik
  • NOSERprojektmanagement
  • NOSERtesting
  • NOSERlifecycle
    • .NET Allgemein
    • Application Lifecylce Management
    • Apps
    • Architektur
    • ASP.NET
    • Azure
    • Cleancode
    • Cloud
    • Silverlight
    • Visual Studio / Team Foundation Server
    • Windows 8
    • Windows Presentation Foundation
  • NOSERinnovation
    • Big Data
    • Cloud
    • IoT
    • Operations Research
    • Augmented Reality
    • RFID, NFC, Bluetooth LE

PhoneGap

21. Dezember 2012
Andreas Schicker
Off
Hybrid, PhoneGap, WebApp
Beim erstellen von WebApp kann man schnell an die Grenzen von JavaScript stossen, da der Browser nur einen limitierten Zugriff auf das Smartphone bietet. PhoneGap bietet dazu die Schnittstelle um auf das Gerät zuzugreifen. PhoneGap Logo

PhoneGap stellt folgende Funktionen zur Verfügung:

Accelerometer Compass Device File Media
Camera Connection Globalization Geolocation Notification
Capture Contacts Events Storage Splashscreen

Dies mag für manche App ausreichen, sobald man allerdings eine native Funktion benötigt, wird ein direkter Zugriff benötigt. PhoneGap bietet eine Lösung über sogenannte „Plugins“ an.

Diese Plugins werden immer mit demselben JavaScript-Code über die PhoneGap Schnittstelle aufgerufen. Das sieht dann in JavaScript so aus:
cordova.exec(pluginSuccess, pluginFail, "TestPlugin", "testAction", ["test"]);

Ich kann hier anmerken das PhoneGap und Cordova das selbe ist.

Der exec Funktion werden zwei Callbackfunktionen, der Plugin Name, die gewünschte Action und ein Array von Parametern übergeben, welche anschliessend der Action im Plugin geliefert werden.

Für jede Zielplattform muss das Plugin dann in der jeweiligen Programmiersprache implementiert werden. In den Pluginklassen kann dann grundsätzlich alles gemacht werden, was auch in der Nativeentwicklung möglich wäre. Sobald die Ausfühung des Plugins fertig ist, kann man den Programmlauf zurück zu den Callbackfunktionen im JavaScript senden. Eine solche Plugin Action könnte in Android wie folgt aussehen:
private void testAction(String message, CallbackContext callbackContext) {
  if (message != null && message.length() > 0) {
    callbackContext.success(message);
  } else {
    callbackContext.error("Expected one non-empty string argument.");
  }
}

Windows Phone 7/8:

public void testAction(string message) {
 if (message != null && message.Length > 0) {
     DispatchCommandResult(new PluginResult(PluginResult.Status.OK, message));
 }
 else {
     DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Error!"));
 }
}

iOS
- (void)testAction:(CDVInvokedUrlCommand*)command
{
CDVPluginResult* pluginResult = nil;
NSString* myarg = [command.arguments objectAtIndex:0];
if (myarg != nil) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Arg was null"];
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }

Die fett markierten Funktionen sind hierbei die Aufrufe der Callbackfunktionen. Das Resultat kann somit zurück zum JavaScript gegeben werden, wo dieses verarbeitet wird. Beispiel von JavaScript Callbackfunktionen:

function pluginSuccess(message) {
// Success callback
 alert("Message:"+message);
}

function pluginFail(message) {
// Error callback
 alert("Error:" + message);
}

Unten sind die Ausgaben auf verschiedenen Geräten sichtbar:

(Windows Phone, Android, iOS)

Ausgabe Windows-Phone Ausgabe Android Ausgabe iOS

viagra online

viagra natural sin receta

Android Runtime Overview in JavaSpektrum 04/2011

23. August 2011
Andreas Schicker
0

Joerg Pleumann, Noser’s Head of Android Development, has scored yet another article in JavaSpektrum magazine. This one is a follow-up to his 2010 article on the Dalvik Virtual Machine, and it explains the Android Core Java Libraries in detail, also comparing them to a standard Java Runtime Library. Find the full PDF here or buy JavaSpektrum (recommended).

Research Papers. Of all of the assignments, this one presents the greatest challenge to undergraduate students. Doing good research and writing requires a research paper online If you buy essay, buy term papers or buy research papers etc you can freely order any citation style – MLA, APA, Chicago, Harvard or Turabian. No matter what

.as exclusivity go Gateway all phone It iPhone effecting the being iphone 3g unlock restriction download uncovering is very of work pushes apps the you

by Martin Straumann

123

Tag Cloud

.NET android Angular AngularJs Arduino ASP.Net automated testing Azure Big Data C# C++ Cloud continuous integration Elm Embedded Führung gRPC Internet of Things IoT Java Javascript M2M OWASP Projektmanagement protobuf Python Raspberry Pi Reactive Programming REST Scrum Security Softwarequalität SPA Testen testing Testmanagement Teststrategie UX Visual Studio WebAPI windows WPF Xamarin Xamarin.Android Xamarin.Forms

Archive

Current Posts

  • Akzente setzen mit der Android Splash Screen API unter .NET MAUI
  • Do You have Your Personal Space?
  • Automated provisioning with ARM Templates
  • Asynchrone Beobachtungen und Versprechungen in Angular
  • Simplify Your Automated Tests With Fluent Syntax

Last Comments

  • Hans Reinsch bei Der Safety-Plan: Die wichtigsten Antworten mit Checkliste
  • George H. Barbehenn bei Modeling Optocouplers with Spice
  • Noser Blog Touch-Actions in Xamarin.Forms - Noser Blog bei Mach mehr aus Animationen in Xamarin.Forms mit SkiaSharp
  • Noser Blog Focus on the Secure Storage service of Trusted Firmware (TFM) - Noser Blog bei First run of the Trusted Firmware (TFM) application
  • Noser Blog First run of the Trusted Firmware (TFM) application - Noser Blog bei Focus on the Secure Storage service of Trusted Firmware (TFM)

Popular Posts

Xamarin.Android Code Obfuscation

6 Comments

ManuScripts: Wenn jemand eine Reise tut... Funktionale Programmierung mit Elm - Teil 1 - Aufbruch

5 Comments

ManuScripts: Wenn jemand eine Reise tut... Funktionale Programmierung mit Elm - Teil 2 - Kein Picknick

4 Comments

Contact us

  1. Name *
    * Please enter your name
  2. Email *
    * Please enter a valid email address
  3. Message *
    * Please enter message
© 2013 NOSER ENGINEERING AG. All rights reserved. Datenschutz | Cookie-Richtlinie