When I ported a Cordova app to Android 5 (Lollipop), I noticed, that the login does not work anymore. In prior versions of Android it works like a charm (app login is based on session cookies).

Part of the Android Lollipop changes:
Apps that target KITKAT or below default to allowing third party cookies. Apps targeting LOLLIPOP or later default to disallowing third party cookies.
https://developer.android.com/reference/android/webkit/CookieManager.html 
Android 5.0 changes the default behaviour for your app.
If your app targets API level 21 or higher:
The system blocks mixed content and third party cookies by default. To allow mixed content and third party cookies, use the setMixedContentMode() and setAcceptThirdPartyCookies() methods respectively.
The system now intelligently chooses portions of the HTML document to draw. This new default behaviour helps to reduce memory footprint and increase performance. If you want to render the whole document at once, disable this optimization by calling enableSlowWholeDocumentDraw().
If your app targets API levels lower than 21: The system allows mixed content and third party cookies, and always renders the whole document at once.
https://developer.android.com/about/versions/android-5.0-changes.html#BehaviorWebView

Indeed, if the app rely on session cookies it will stop working as expected.

However. Here is a fix to make session cookies work again on Android Lollipop and above:

/*
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.
 */

package com.blogspot.tol8;

import android.os.Bundle;
import org.apache.cordova.*;
import android.os.Build;
import android.webkit.CookieManager;
import android.webkit.WebView;

public class MyApp extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.init();

        // Allow third party cookies for Android Lollipop
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        {
                WebView webView = (WebView)super.appView;
                CookieManager cookieManager = CookieManager.getInstance();
                cookieManager.setAcceptThirdPartyCookies(webView,true);
        }
        super.loadUrl(Config.getStartUrl());
    }
}

BTW: Make sure that you use the latest Android SDK to compile the source code. I have also created an issue at the Cordova bug tracker (https://issues.apache.org/jira/browse/CB-8026).


Some years ago, I faced this bug in MySQL Workbench:
  1. Create a table
  2. Add a column with type datetime
  3. Go to the query editor
  4. Try to insert now() into the datetime field
Result: It will not work.

Reason, if you take a look at the query you will see the following:
`test_date`='now()'
Ok, the solution is easy, "now()" must be written without the single quotes. To do this type: 

\func now() 

instead of 

now()



Today I will tell you how to get reliable geolocation data on Cordova or Phonegap. It took me a lot of time to figure all this out, so I hope that I can save you some precious time with my article.

Note: I tested on Cordova 3.4.x and Android/WindowsPhone.

Before we start, make sure that you have not installed the Cordova or Phonegap geolocation plugin! In case you already have, remove it with the following command "cordova plugin remove org.apache.cordova.geolocation". We do not need this plugin since the native HTML5 support is much better! Further information can be found here. I don't know why this plugin is still available in the official documentation... But don't worry if you come from Cordova or Phonegap, you don't have to change a lot in your existing code (maybe you have to eliminate the frequency attribute).

Please pay attention that, also when you are not using the geolocation plugin, you have to set the following privileges in your:

AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
WPAppManifest.xml

<Capabilities>
               <Capability Name="ID_CAP_LOCATION" />
</Capabilities>
The code for the implementation itself is relative trivial. I would suggest you to implement it after the following action plan:

  • Before you do anything, check if geolocation is available (navigator.geolocation)
  • Try to get the current position with high accuracy, if the request timed out or an error occur > fallback to lower accuracy.
Important parameter:
  • enableHighAccuracy: true/false for high or low accuracy
  • maximumAge: Accept a cached position whose age is no greater than the specified time in milliseconds. (Number)
  • timeout: Maximum time of lenght in ms to get the position.
  • frequency: Stop using this attribute. It is not W3C compliant. Use maximumAge instead!
Suggested values:
  • enableHighAccuracy: true, maximumAge:3000, timeout: 5000
  • enableHighAccuracy: false, maximumAge:3000, timeout: 30000

Tips:
  • If you want to update your geolocation data continuously, use watchPosition(...) instead of getCurrentPosition(...). Also use the pause/resume functions of Cordova/Phonegap to start/stop the watch while the application is or return from background. The users battery will thank you.
  • Keep in mind that the logic behind getCurrentPosition(...) and watchPosition(...) is differently on different devices. So test your implementation as much as you can!


Please let me know if this article helped you to improve your geolocation results. If you tested successfully with iOS drop a comment (ideal with required privileges) as well. Thanks!


In this article I would like to show you how an app is published with multiple languages ​​to the Windows App Store.

As default, you can only select one default language on the Windows App Store. In order to add more languages, the language information must be added before uploading the XAP file.

In Visual Studio, go to Project Explorer > Solution > Project > Properties and open the WMAppManifest.xml file.

Switch to the tab "Packaging" and add the specific languages. Save the changes, rebuild the XAP file and upload it again. After uploading the XAP file, now you can select multiple languages.




In this article I would like to show you how to create a XAP file for the Windows App Store.

  1. Open MS Visual Studio
  2. Open your project
  3. Go to the "Project Explorer"
  4. Right click on the Solution > Properties
  5. Change the build properties as illustrated in the screen below
  6. Apply the changes
  7. Build your project ("F7")
  8. Make sure that the build was successful (console output)
  9. Open your project in the Windows Explorer and search for "*.xap". Choose the release version. Done.



Most of the lists in Sencha Touch are connected to a store. When the store only contains a small amount of records, performance is not a problem. However, when the store is filled with a big amount of records, it is very important that the data is added in an optimum manner.

Let's have a look at the following code:
copyObjects : function(objects) {
   var taskModel = null, 
       taskStore = Ext.getStore('Tasks');

   taskStore.removeAll(true);

   Ext.Array.each(objects, function (data) {
      taskModel = Ext.create('MyApp.model.Task', data);
      taskModel.setDirty(true);
      taskStore.add(taskModel);
   });
   taskStore.sync();
}
In the above example, 100 objects are added. Tested on a Samsung Galaxy II, the execution takes 12 to 14 seconds. It simply takes too long!

After further testing, I found out that the add function takes so much time (http://docs.sencha.com/touch/2.3.1/source/Store.html # Ext-data-store-insert method). Therefore, the solution is to call this function as less as possible. This can be done with a temporary array:
copyObjects : function(objects) {
   var taskModel = null, 
       taskStore = Ext.getStore('Tasks'),
       tmp = new Array();

    taskStore.removeAll(true);

    Ext.Array.each(objects, function (data) {
       taskModel = Ext.create('MyApp.model.Task', data);
       taskModel.setDirty(true);
       tmp.push(taskModel)
    });
    taskStore.add(tmp);
    taskStore.sync();
}
The execution time takes only one second now.

Advice: Pay attention that your list is not too long, because the scrolling performance will go down as well.


I think everyone who deploy a first app on Windows Phone is facing the same problem: The app is running fine, but where the heck are my icons?

Apparently there is an issue present in Windows Phone 8 that prevents custom font-faces from working when HTML and CSS are hosted locally.

So we came up with the first solution: Hosting everything remote. But really, this is not a solution, right?

After spending some more time on google, I found another solution: Including the font-file instead of the base 64 encoded font.

Sample Code:
@font-face {
 font-family: 'Pictos';
 src:url('fonts/pictos-web.woff') format('woff');
 font-weight: normal;
 font-style: normal;
}
However, this code never worked for me. Some user reported that it works, but the rest said that it doesn't work for them too or only for some and not all of their font files.

Finally I came up with another idea: When I cannot rely on the CSS font-face, then I'll go back to the roots and display pictures instead. Of course this costs more effort and is not as elegant as using icon fonts, but so far this seems to be the only safe solution to get it done.

Before we start, let me tell you that we don't have to modify any of the Java Script Code and it will not affect other platforms like Android or iOS.

If you are already working with Themes (what I would suggest you) then you can just place the new CSS code to your WP.scss

To reduce the CSS markup, I created a small mixin. In this mixin we set a new background image with height and width, also we replace the characters in content with an empty string:

@mixin wpIcon($name,$dim) {
  $url:"../images/wp/#{$name}.png";
  background: transparent url($url) 0 0 no-repeat;
  content: '';
  height: $dim;
  width: $dim;
  display: inline-block;
}

The sample code above requires that your images are located in "/resources/images/wp".

Replacing images is very straight forward, lets take a look at another sample which shows how to use this mixin:
/* Replace the checkbox checked icon */
.x-input-checkbox:checked ~ .x-field-mask:after {
  @include wpIcon(checkmark, 20px);
}

/* Replace the back button icon and add a second rule for back button pressed */
.x-button-back:before {
  @include wpIcon(arrow-left, 32px);
}

.x-button-back.x-button-pressing:before {
  @include wpIcon(arrow-left-pressed, 32px);
}
As you can see we just pass the image name (without the file extension) + a size to the mixin.

If you don't use the WP.scss yet you can add ".x-windowsphone" as an additional class to your CSS rule. This makes sure that the rule will only apply on Windows Phone.

I hope this trick help you to get your icons back on Windows Phone. Please let me know when you have even a better idea/solution for this problem.