Tuesday, September 29, 2015

Phone calls Windows Phone 8 vs. Windows Phone 8.1

Problem:

I am migrating a windows phone 8 app to windows phone 8.1.  The move forward involved changes to the namespaces where the phone tasks occur

Solution:

Making a call in Windows Phone 8
  1. Add the following statement to your code.
    using Microsoft.Phone.Tasks;
  2. Add the following code to your application wherever you need it, such as in a button click event. To test this procedure, you can put the code in the page constructor. This is the code to launch the task.

    PhoneCallTask phoneCallTask = new PhoneCallTask();
    phoneCallTask.PhoneNumber = "2065550123";
    phoneCallTask.DisplayName = "Gage";
    phoneCallTask.Show(); 


Making a call in Windows Phone 8.1

Add the following code to your application wherever you need it, such as in a button click event. To test this procedure, you can put the code in the page constructor. This is the code to launch the task.


Windows.ApplicationModel.Calls.PhoneCallManager.ShowPhoneCallUI("phone number", "display name");

    Source:

    1. https://msdn.microsoft.com/de-de/library/windows/apps/hh394025(v=vs.105).aspx
    2. http://stackoverflow.com/questions/23555640/make-a-phone-call-in-windows-phone-8-1


    Access Existing SQLite database in Crossplatform solutions

    Background:

    I am trying to build out a crossplatform mobile solution using MVVMCross.  Stuart Lodge's N+1 series does a great job explaining how to use a new sqlite database.  The missing use case is how to implement the solution for an existing sqlite database.  I am working on that solution currently.

    Problem:

    My immediate issue was how to get the Windows Phone sqlite database from the installation into the app storage.

    Solution:

    private async Task CopyDatabase()
    {
        bool isDatabaseExisting = false;
        try
        {
            StorageFile storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync("people.db");
            isDatabaseExisting = true;
        }
        catch
        {
            isDatabaseExisting = false;
        }
        if (!isDatabaseExisting)
        {
            StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("people.db");
            await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);
        }
    }



    Source:

    1. http://wp.qmatteoq.com/using-sqlite-in-your-windows-8-metro-style-applications
    2. http://wp.qmatteoq.com/import-an-already-existing-sqlite-database-in-a-windows-8-application/

    Wednesday, September 23, 2015

    How to get connection and carrier information in Windows Phone 8.1 Runtime

    Problem:

    I have been using the MVVMCross Connectivity plugin for a project.  I went to upgrade the
    WP UI to windows phone 8.1 and hit issues immediately.  This is due to the Inversion of Control
    layer for Windows Phone in the plugin.  The plugin is using deprecated functionality mainly the DnsEndPoint as part of the Microsoft.Phone.Net namespace.  This is how the plugin is determining if a phone is connected. This requires the change be applied for IsPingReachable method in the Connectivity class in the Windows Phone UI layer for the plugin.

    Solution:

    Update the connectivity library for MVVMCross with this info

    1.) Test for internet connection on Phone

      //Get the Internet connection profile
        string connectionProfileInfo = string.Empty;
        try {
            ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

            if (InternetConnectionProfile == null) {
                NotifyUser("Not connected to Internet\n");
            }
            else {
                connectionProfileInfo = GetConnectionProfile(InternetConnectionProfile);
                NotifyUser("Internet connection profile = " +connectionProfileInfo);
            }
        }
        catch (Exception ex) {
            NotifyUser("Unexpected exception occurred: " + ex.ToString());
        }

    2.) Get Connectivity properties for Windows Phone 8.1

    using Windows.Networking.Connectivity;
    
    /// <summary>
    /// Detect the current connection type
    /// </summary>
    /// <returns>
    /// 2 for 2G, 3 for 3G, 4 for 4G
    /// 100 for WiFi
    /// 0 for unknown or not connected</returns>
    private static byte GetConnectionGeneration()
    {
        ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();
        if (profile.IsWwanConnectionProfile)
        {
            WwanDataClass connectionClass = profile.WwanConnectionProfileDetails.GetCurrentDataClass();
            switch (connectionClass)
            {
                //2G-equivalent
                case WwanDataClass.Edge:
                case WwanDataClass.Gprs:
                    return 2;
    
                //3G-equivalent
                case WwanDataClass.Cdma1xEvdo:
                case WwanDataClass.Cdma1xEvdoRevA:
                case WwanDataClass.Cdma1xEvdoRevB:
                case WwanDataClass.Cdma1xEvdv:
                case WwanDataClass.Cdma1xRtt:
                case WwanDataClass.Cdma3xRtt:
                case WwanDataClass.CdmaUmb:
                case WwanDataClass.Umts:
                case WwanDataClass.Hsdpa:
                case WwanDataClass.Hsupa:
                    return 3;
    
                //4G-equivalent
                case WwanDataClass.LteAdvanced:
                    return 4;
    
                //not connected
                case WwanDataClass.None:
                    return 0;
    
                //unknown
                case WwanDataClass.Custom:
                default:
                    return 0;
            }
        }
        else if (profile.IsWlanConnectionProfile)
        {
            return 100;
        }
        return 0;
    }
     
    
    


    Source

    1. https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh452991.aspx
    2. http://stackoverflow.com/questions/24003786/how-to-get-connection-and-carrier-information-in-windows-phone-8-1-runtime

    Java library file C:\Users...\AppData\Local\Xamarin\Android.Support.v4\21.0.3\embedded\classes.jar doesn't exist.

    Problem:

    I installed the Xamarin Android Support Library v7 AppCompat nuget package into my project.  When I go to build it out I get prompted with the error:

    C:\Program Files (x86)\MSBuild\Xamarin\Androi\Xamarin.Android.Common.targets(236,2): 
    error XA5207: Please install package: 'Android Support Library' available in SDK installer. 
     Java library file C:\Users...\AppData\Local\Xamarin\Android.Support.v4\21.0.3\embedded\classes.jar doesn't exist.

     

    Solution:

    Delete folder: 21.0.3 (...\AppData\Local\Xamarin\Android.Support.v4\21.0.3)

    Source:

    http://stackoverflow.com/questions/28437601/error-after-updating-the-android-support-library-v7-appcompat-to-the-21-0-3-vers

    Friday, September 18, 2015

    MVVMCross navigation issues with Windows Phone 8.1 Silverlight - RootFrame_NavigationFailed

    Problem:

    Had a working Windows Phone 8 project as part of our cross platform solution.  I upgraded the Windows Phone UI to WP Silverlight 8.1.  I immediately began getting strange behaviour on reactivation.

    The issue appeared like so.  I can successfully launch the app and it works with no issues.  I then hit the windows button to take me out of the application.  Upon touching the tile to reactivate, the application loads and then crashes.  This does not occur in the previous Windows Phone 8 version.

    Issue:

    The app activation and deactivation behaves differently in Windows 8.1.  We are using MVVMCross to accomplish our IoC.  Thus for Windows Phone 8, the app.xaml.cs includes an override method in the Application_Launching event which instantiates the IoC to pass control back to the Core for resolution.  This works great in WP8 but due to the changes in navigation in WP8.1, the IoC event does not get called again when the app reloads from memory.  The next issue is that the WP8.1 navigation load overwrites the previous MVVM view in the RootFrame and replaces it with the xaml file specified in the WMAppManifest.xaml file.  This naturally will cause either a crash if you have deleted the MainPage.xaml from your project like I did, or it will load that MainPage.xaml instead of the correct MVVM view.

    Solution:


    Need to intercept the navigation stack and manually remove the offending page from the stack.
    This can be done by going to the App.xaml.cs page in your Windows Phone project.

    private void Application_Launching(object sender, LaunchingEventArgs e)
    {
          RootFrame.Navigating += RootFrameOnNavigating;
        RootFrame.Navigating += (s, e) =>
        {
        if (e.Uri.ToString().StartsWith("/MainPage.xaml"))
        {
            e.Cancel = true;
        }
        };
    }

    Source
    1. https://msdn.microsoft.com/en-us/library/windows/apps/ff817008%28v=vs.105%29.aspx
    2. http://stackoverflow.com/questions/23324213/mvvmcross-phone-8-1-resume-shows-mainpage-xaml
    3. http://fetchmytip.blogspot.com/2015/08/mvvmcross-systemreflectiontargetinvocat.html

    Tuesday, September 15, 2015

    Android emulators tips

    How to Run Windows 10 Emulator from the command line:

    "C:\Program Files (x86)\Microsoft XDE\10.0.1.0\XDE.exe" /name "Emulator 10.0.1.0 WVGA 4 inch 512MB.rob" /displayName "Emulator 10.0.1.0 WVGA 4 inch 512MB" /vhd "C:\Program Files (x86)\Windows Kits\10\Emulation\Mobile\10.0.1.0\Flash.vhd" /video "480x854" /memsize 512 /diagonalSize 4 /language 409 /creatediffdisk "C:\Users\Rob\AppData\Local\Microsoft\XDE\10.0.1.0\dd.480x854.512.vhd" /snapshot /fastShutdown

    Location of the android player developed by the folks at Xamarin:

    http://developer.xamarin.com/guides/android/getting_started/installation/android-player/

    Run Visual Studio Emulator for Android on Visual Studio 2013 Ultimate

    Trying my hand at some Android programming as I work through the Xamarin courseware.  Man I did not realize how bad the Android emulators are.  Fortunately, MS comes to the rescue with a port of its fine xde which I have used for my WP8 programming.

    I decided to install the emulator after trying to get the existing emulators to run.  I have VS 2013 SP4 running.  I am not ready to upgrade to 2015 since I am in the middle of a project and can't stop to upgrade. 

    Problem:  

    We have a work dev image which is being actively used by our staff.  We are in the midst of testing and release for our crossplatform application.  We are not ready to go to Visual Studio 2015.  We would however like to get the Android emulator for VS working with our current dev install.  We are tired of the Android emulator which is slow and GenyMotion was an extra solution to maintain.  Since we are already familiar with the Windows Phone emulator we wanted to go with the MS Android Emulator.

    Challenge:

    Option 1: Not an option now
    There are any number of blogs that tell you just to upgrade to VS 15 and be done.

    Option 2:  Fail
    Install the standalone emulator (link??) .   I did attempt this but I could not get Visual Studio to recognize the emulator and debug against it.

    Option 3: Solution
    I attempted to do a side by side install of VS 13/15.  This did the trick.  Note this was not a full install of VS 2015 we just added the bare bones to get us the emulator and what was needed to run it.  If you do full install to include all the 3rd party cross platform packages (Xamarin).  You will bork your existing VS 2013 install.

    Solution:

    What needs to be done:
    1. Get an image of VS 2015.  We used VS 2015 Ultimate.
    2. Run up the installer and make the following selections. 
      • Microsoft Web Developer Tools
      • Windows 8.1 and Windows Phone 8.0/8.1 Tools > Emulators for Windows Phone 8.1
      • Microsoft Visual Studio Emulator for Android
    3. The next step is to start up Visual Studio 2015 and let the tool prompt you for Extensions and updates to your new install.
    4. The notifications window will prompt you with a list of options, look for Hyper-V Android Emulator Launch.  Double click on the link. 
    5. Visual Studio Gallery will now be started, select the Hyper-V Android Emulator Launch option. 

    6. Let the install run it will require you to restart VS. 
    7. Now run up your VS 2013 install.  You will now have a new option on the menu.  

    8. This icon is the emulator option.  Once selected the emulator is started in a separate window.
    9. Please note that when you run up your Android project the Launch menu will not display the emulator until it is turned.  Once it is run up then you see the emulator listed in the launch debug menu
       

    10. Now I can run up my sample Android app and debug with VS 2013 against the Android emulator.
       


    Source

    1. https://www.visualstudio.com/en-us/features/msft-android-emulator-vs.aspx
    2. https://canbilgin.wordpress.com/2015/02/17/android-emulator-launcher-for-visual-studio-2013/
    3. https://visualstudiogallery.msdn.microsoft.com/4201105a-fb80-48c0-ad42-b163802c9f61
    4. http://stackoverflow.com/questions/28239195/debugging-cordova-app-android-with-visual-studio-2015-new-emulator
    5. http://stackoverflow.com/questions/28253436/visual-studio-emulator-for-android-in-visual-studio-2013
    6. http://stackoverflow.com/questions/31613607/visual-studio-2015-emulator-for-android-not-working-xde-exe-exit-code-3
    7. http://developer.xamarin.com/guides/android/getting_started/installation/android-player/
    8. https://msdn.microsoft.com/en-us/library/dn757059(v=vs.120).aspx

    Tuesday, September 8, 2015

    Enable Boot to VHD with Windows 10

    Problem:


    I am building out a development environment to run in the office.  I decided to update my vhd builds to windows 10 from Windows 8.1.  The last time I did this was with Imagex.  Things have moved on and now Imagex has been depreciated. The new tool is DISM and is part of the OS starting in Windows 8.

    Solution:

    1. In your host OS, Create the VHD with disk management (See Technet article)
    2. Now the command to move the WIM image
      • DISM /Apply-Image /ImageFile:D:\Sources\install.wim /Index:1 /ApplyDir:V:\
        where D is the drive mounted with the windows 10 disk and V: is the vhd mount
    3. Change the boot menu to boot to vhd on your c drive.
      • bcdedit /copy {GUID} /d "New Name"
      • bcdedit /set {GUID} osdevice vhd=[C:]\folder\filename.vhd  
      • bcdedit /set {GUID} device vhd=[C:]\folder\filename.vhd
        • Note: I got tripped up on the exact syntax for bcdedit. The brackets around the drive letter are required. If you leave them off you will get a syntax error.
      • bcdedit /default {current}
      • bcdedit /set description "Windows 10 VHD"


    Source:

    1. https://technet.microsoft.com/en-us/windows/dn858566.aspx
    2. http://mythoughtsonit.com/2013/02/dism-exe-replaces-imagex-exe/
    3. http://blogs.technet.com/b/jamesone/archive/2009/05/19/boot-from-vhd-the-joy-of-bcdedit-and-a-nice-hyper-v-gotcha-or-two.aspx

    Playing with DISM

    I was looking for information on DISM tool since I have not used it before.  I have put on my Sys Admin hat to build out some new development environments.  I found this great article by Brian Lewis.  He explains how to use DISM to  capture your current working drive.  This will enable me to capture my current development image and push it onto a vhd for use by our staff.  Brian is using a usb stick to capture the image. 

    Here are the steps that I use:
    1. Boot off of a Windows 8/10 install USB stick (See my post on how to create a USB install stick)
    2. At the install Screen hit <shift> <F10> to start a CMD prompt window
    3. To Capture the C: Drive to an external USB drive
      1. Dism /Capture-Image /ImageFile:d:\my-image.wim /CaptureDir:c:\ /Name:”My Image”
    4. To Restore this Image from the external USB drive
      1. Dism /apply-image /imagefile:d:\my-image.wim /index:1 /ApplyDir:c:\

     Source:

    http://mythoughtsonit.com/2013/02/dism-exe-replaces-imagex-exe/