Quantcast
Channel: SCN : All Content - SAP for Mobile
Viewing all articles
Browse latest Browse all 6147

Getting Started with Kapsel - Appendix F -- Tips

$
0
0

http://scn.sap.com/servlet/JiveServlet/downloadImage/333927/sap-logo.png

 

 

Appendix F:  Tips

Where to Get Help with Cordova Questions
Adding the WTP HTML and JavaScript Editors to Eclipse
Monitoring TCP/IP Requests
Customizing and Reducing the Project Size
Setting the Session Timeout for the Management Cockpit
Accelerating the Android Emulator
Proxy Settings on Android
iOS 7 Status Bar Overlays the App
Enabling Landscape Orientation on an iPhone
Simple Customizations
Opening URL's
Miscellaneous Tips

Where to Get Help with Cordova Questions

There is an active forum on PhoneGap/Cordova at PhoneGap Forum.

 

The list of known Cordova issues can be searched at Apache Cordova Issue Tracker.

 

The Cordova mailing lists can be searched at Apache Cordova Mailing Lists.

 

 

Adding the WTP HTML and JavaScript Editors to Eclipse

By default the Android ADT Eclipse bundle does not contain the Web Tools editors.  These can be added by choosing Help > Install New Software... > Juno >  Web, XML, Java EE and OSGi Enterprise Development > JavaScript Development Tools and Web Page Editor.
image5.PNG

 

After restarting Eclipse, right click on an HTML or JavaScript file and open it with the appropriate editor.image6.PNG

 

The default editor for a certain file type can be set under Window > Preferences > General > Editors > File Associations

 

 

Monitoring TCP/IP Requests

It can be useful to examine the REST calls made between an application and the SMP 3.0 server.  One way to do that is to use the Eclipse TCP/IP monitor which is included as part of the Web Tools Project.

  • Add the TCP/IP Monitor by installing Eclipse Web Deveoper Tools.  In eclipse choose Help > Install New Software... > Work with Juno > Web, XML, Java EE and OSGI Enterprise Development > Eclipse Web Developer Tools.
  • Configure the TCP/IP Monitor and ensure that it is started.
    image8.PNG
  • Make requests from a Kapsel app such as a registration and read request using the port that the TCP/IP Monitor is listening on.  In this example, set the port on the Registration screen of the Logon plugin to use port 85.
  • The REST calls between the Kapsel app and the SMP 3.0 server can be observed.
    image9.PNG

The SMP 3.0 server can also log all http requests.

  • To enable this feature, modify C:\SAP\MobilePlatform3\Server\config_master\org.eclipse.gemini.web.tomcat\default-server.xml and uncomment the entry <Valve className="org.apache.catalina.valves.AccessLogValve".

  • Restart the SMP 3.0 server.

  • After making some requests to the SMP 3.0 server examine the log file at C:\SAP\MobilePlatform3\Server\log\localhost_http_access_2014-04-29.log.
  • 10.7.171.196 - - [29/Apr/2014:16:58:28 -0400] "OPTIONS /odata/applications/latest/com.mycompany.timing/Connections HTTP/1.1" 200 - 146
    10.7.171.196 - i826567 [29/Apr/2014:16:58:28 -0400] "POST /odata/applications/latest/com.mycompany.timing/Connections HTTP/1.1" 201 1704 453
    10.7.171.196 - - [29/Apr/2014:16:58:30 -0400] "OPTIONS /com.mycompany.timing/FlightCollection HTTP/1.1" 200 - 3
    10.7.171.196 - i826567 [29/Apr/2014:16:58:33 -0400] "GET /com.mycompany.timing/FlightCollection HTTP/1.1" 200 582225 3038

    The second last entry indicates the response size and the last entry indicates the duration in milliseconds that the operation took.  The last operation returned 569KB and took approximately 3 seconds to complete.

Customizing and Reducing the Project Size

The default project created by running

cordova create ...

is copied from

C:\Users\user_name\.cordova\lib\www\cordova\3.x\www

or

/Users/user_name/.cordova/lib/www/cordova/3.x/www

As such if there are files that you always wish to include in new Kapsel projects such as datajs-1.1.2.min.js they can be included here.  Alternatively if you wish to not include certain files, they can be removed. 
Note that in Cordova 3.4, the create command supports a --src parameter which specifies the location to get the contents for the assets folder of the newly created project.  See CB-4153

 

Note, on iOS .folders are hidden by default.  They can be made viewable by

defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder

 

Setting the Session Timeout for the Management Cockpit

The duration after which the Management Cockpit by default times out and requests the user to log in again is 20 minutes from the last use.  This value can be changed by modifying the session-timeout setting in the following file and restarting the SMP 3.0 server.

C:\SAP\MobilePlatform3\Server\config_master\org.eclipse.gemini.web.tomcat\web.xml

Note that if the same browser that is hosting the Management Cockpit is also used to say invoke a REST call against the SMP 3.0 server and uses a different security profile, the Management Cockpit is logged out.  An example of this is using the Chrome Advanced Rest Client to send a push notification as described in the section Push.

 

Accelerating the Android Emulator

There are two ways that the Android emulator can be configured to run faster.  The first way uses graphics acceleration to increase the redraw rate of the emulator.  It can be enabled by checking Use Host GPU
image1.PNG

 

Note you may run into screen redraw issues after enabling this option.

 

The second way is to use virtual machine acceleration.  This requires the download of the Intel Hardware Accelerated Execution Manager. 
image2.PNG

 

 

    It then needs to be installed.

C:\Android\adt-bundle-windows-x86_64-20130729\sdk\extras\intel\Hardware_Accelerated_Execution_Manager\IntelHaxm.exe

An Android X86 based image, Intel Atom (x86) must be selected.
image7.PNG

 

Note that after starting the emulator; the following message appears indicating that it is working correctly.  image3.PNG

 

 

 

For additional details see Using Hardware Acceleration

 

 

Proxy Setting for Android

If you use a proxy server, the Android emulator can be configured under Settings > More > Mobile Networks > Access Point Names.
image4.PNG

 

To set the proxy settings for an Android device that is using WIFI, go to Settings > Wireless and Network > Wi-Fi Settings > Long press on the Wi-Fi network > Check the Show Advanced Options.
A quick way to test if the proxy settings are working is to open the browser and attempt to access a web site such as http://www.google.com.

 

 

iOS 7 Status Bar Overlays the App

If your app runs on iOS 7 you may need to add a 20 pixel top margin so that the status bar does not overlay the main screen of the application.  The Status Bar Issue describes the problem in more detail and contains the following solution.

document.addEventListener('deviceready', onDeviceReady, false);
function init() {    if (parseFloat(window.device.version) >= 7.0) {          document.body.style.marginTop = "20px";    }
}  

      A SAP UI5 specfic solution is shown below.

html[data-sap-ui-os^="iOS7"] .sapMBar {  border-top-color:#F2F2F2;  border-top-style:solid;  border-top-width:20px;
}

Enabling Landscape Orientation on an iPhone

If you rotate an iPhone device or simulator, the HTML page does not rotate to support the new orientation.  To add this ability, in Xcode, under Info > Custom iOS Target Properties > Supported interface orientations, add the missing interface orientations such as Landscape (left home button).

 

 

Simple Customizations

There are a few easy ways to quickly customize your app including adding a gradient, removing the default Cordova splash screen and changing the app icon.  Additional information on app icons and splashscreens can be seen at Splashscreen.

  • To add a gradient use a tool like Ultimate CSS Gradient Generator to generate a line of CSS that can be added to the top of your index.html.
    <head>
         <style>
             body {background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#feffff), color-stop(35%,#ddf1f9), color-stop(100%,#a0d8ef));}   </style>
  • To change the splash screen on iOS, left-click on the Project > Target > scroll to Launch Images, right-click on the image that matches the device type being used and choose open with Finder.    Replace that image with a new image that has the appropriate resolution.  The same approach can be followed to change the app icon.
  • To change the app icon on Android, replace the icon image with a new image that has the appropriate resolution.  The icon images are located in the following folder.
    project_name\platforms\android\res\drawable-xxxx.

Note that cleaning the project may be necessary after changing the icon or splash screen.

 

 

Opening URL's

To open an external URL from index.html, the Cordova InAppBrowser plugin can be used.

<script>
     function showURL(url) {       var URLToOpen = encodeURI(url);  //may be needed if URL contains parameters         var ref = window.open(URLToOpen, '_blank', 'location=yes');  //location bar shown or not    }</script>
<a href="javascript:void(0);" onclick="showURL('http://www.google.com')">www.google.com</a>

This will open a new window showing the web site www.google.com.  When the window is closed, the Kapsel app will regain focus.

 

Note that local HTML files can simply be opened using

<a href="accounts.html">Open Accounts</a>

Note that on Android, if the resource does not exist and the link is clicked on the app will close.  To instead shown an error screen, modify the config.xml file under the res/xml folder to include a preference setting indicating an error page to open.

<preference name="errorUrl" value="file:///android_asset/www/error.html" />

See Android Configuration for additional details.

 

 

Miscellaneous Tips

  • Sometimes in Xcode it is necessary to perform a more complete clean of a project.  This can be performed by holding the Alt key when selecting the Product menu.  The Clean menu item changes to Clean Build Folder...
  • The iOS simulator can be reset to a clean state.  This can be performed by choosing iOS Simulator > Reset Content and Settings...
  • To delete an app on iOS, long press on the app icon.
  • An iOS app can be removed from memory by pressing the home button twice quickly.  On iOS 7 swipe the app up to remove it.
  • See Interacting with iOS Simulator for details on things such as how to rotate, drag and pinch.
  • An Android app can be uninstalled or reset to a newly deployed state via Settings > Apps > App > Uninstall or Clear Data.  A quicker way to do this is to long press on the app and then drag the icon to Uninstall or App Info.
  • If the application running in an Android emulator takes a while to load it may be necessary to increase the loadUrlTimeout value.  This can be set in the Java class for the plugin.
    public class LogonDemo extends DroidGap
    {    @Override    public void onCreate(Bundle savedInstanceState)    {        super.setIntegerProperty("loadUrlTimeoutValue", 60000);   //add this line.        super.onCreate(savedInstanceState);        // Set by <content src="index.html" /> in config.xml        super.loadUrl(Config.getStartUrl());        //super.loadUrl("file:///android_asset/www/index.html")    }
    }
    See also Android Configuration.
  • Occasionally the logcat view stops displaying messages from the attached Android or simulator.  Sometimes, switching to the DDMS perspective and clicking on a few entries in the Devices view corrects this.  Also make sure that no filters or regular expressions are being accidentally applied.
  • If the SMP 3.0 Management Cockpit fails to open, one reason may be that another process is using port 8083.  To view which process is using port 8083 enter
    netstat -ano | findstr 8083
    TCP    [::]:8083              [::]:0                 LISTENING       8092
    Using the above information we can see that a process with the process ID of 8092 is using port 8083.  Open the task manager on windows and add the PID column and check Show processes from all users to find the process that is using port 8083.  The SMP 3.0 server should appear as a java.exe process and a description of SAP Java VM Runtime binary.

 

Back to Getting Started With Kapsel


Viewing all articles
Browse latest Browse all 6147

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>