Search code examples
windows-phone-7windows-phonelive-tile

New Tile with special start of application in WP7


I've got question. I have application which is a phone book. I would like to create Tile (in Windows Phone main screen) which'll call that number after I click Tile on main screen.

Is that possible? What should I do to make something like that? I can create custom Tile or maybe I should create some method after my application start?


Solution

  • Create the live tile with something like the following code:

    string number = "000 - 000 000";
    ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault(t => t.NavigationUri.ToString().Contains("phone=" + number));
    
    if (tile == null)
    {
       StandardTileData tileData = new StandardTileData();
       tileData.Title = "Call " + number;
       ShellTile.Create(new Uri("/MainPage.xaml?phone=" + number, UriKind.Relative), tileData);
    }
    

    And then override the OnNavigatedTo in MainPage.xaml, and add the following code:

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
       if (NavigationContext.QueryString.ContainsKey("phone"))
       {
           string number = NavigationContext.QueryString["phone"];
           PhoneCallTask task = new PhoneCallTask();
           task.PhoneNumber = number;
           task.Show();
        }
        base.OnNavigatedTo(e);
    }
    

    If you have not done it yet, you also need to add the "ID_CAP_PHONEDIALER" capability in the WMAppManifest.xml file, or you will get an exception when calling task.Show(); above.

    Now you got a live tile that when clicked will launch the application and call the number (The user must still confirm it in a dialog though, and that is something you can't disable)