How to programatically create a tile in Windows Phone 8.1? - windows-phone-8.1

In Windows Phone 8 I was able to create a Shell Tile with the following:
StandardTileData newTileData = new StandardTileData
{
BackgroundImage = new Uri("/Images/my_tile_medium.png", UriKind.Relative),
Title = "My Tile Title",
BackTitle = "My Tile Back",
BackBackgroundImage = new Uri("/Images/my_tile_medium_back.png", UriKind.Relative),
};
ShellTile.Create(MyAppPages.MainPage("Name=MyAppTile"), newTileData);
This no longer works in Windows Phone 8.1. How can I programatically create a tile with Windows Phone 8.1

In WP8.1 Runtime you can use SecondaryTile, for example:
SecondaryTile tileData = new SecondaryTile()
{
TileId = "MyTileID",
DisplayName = "MyTilesTitle",
Arguments = "Some arguments"
};
tileData.VisualElements.Square150x150Logo = new Uri("uri to image");
tileData.VisualElements.ShowNameOnSquare150x150Logo = true;
await tileData.RequestCreateAsync();
Some guide you can also find here at MSDN.

Related

ZXing.Net.Mobile in Windows Phone 8.1

I am using ZXing.Net.Mobile in my windows phone 8.1 app. It is using below reference:
ZXing.Net.Mobile.Core
zxing.portable
ZXingNetMobile
My Code :
var scanner = new MobileBarcodeScanner();
MobileBarcodeScanningOptions options = new MobileBarcodeScanningOptions();
options.TryHarder = true;
options.PossibleFormats.Add(ZXing.BarcodeFormat.CODE_128);
options.PossibleFormats.Add(ZXing.BarcodeFormat.CODE_39);
var result = await scanner.Scan(options);
if (result != null)
{
MessageDialog a = new MessageDialog(result.Text);
a.Content = result.Text;
a.ShowAsync();
}
Issue:
Am getting below issue whenever scan method executes.
Use the platform specific implementations instead at ZXing.Mobile.MobileBarcodeScanner.Scan(....
Is there any real time QR code scanner available for windows phone 8.1 ?

Windows Phone 8.1 AppBarButton with custom BitmapIcon

I want to create a custom image for the AppbarButton.
I'm using code from
Windows Phone 8.1 AppBarButton icon with 2 rows of text
RenderTargetBitmap rtb = new RenderTargetBitmap();
await rtb.RenderAsync(TodayTextBorder);
IBuffer pixels = await rtb.GetPixelsAsync();
string filename = "TodayIcon.png";
var outputFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(filename, Windows.Storage.CreationCollisionOption.ReplaceExisting);
using (var outputStream = await outputFile.OpenAsync(FileAccessMode.ReadWrite))
{
BitmapEncoder enc = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, outputStream);
var dpi = DisplayInformation.GetForCurrentView().LogicalDpi;
enc.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, (uint)rtb.PixelWidth, (uint)rtb.PixelHeight, dpi, dpi, pixels.ToArray());
await enc.FlushAsync();
}
BitmapIcon icon = new BitmapIcon();
icon.UriSource = new Uri("ms-appdata:///local/" + filename);
TodayAppbarButton.Icon = icon;
But it doesn't work. Well, it works on the Emulator and on the phone in case the app was deployed directly from Visual Studio. But when I'm publishing app and installing it from the Store I'm getting erroneous appbar button image (like this http://i.imgur.com/de73cTo.png)

How to show map with pushpin for given latitude and longitude in windows phone 8

I'm new to windows phone 8 application. Could you please help me how to show a Map with pushpin for the given Latitude and Longitude in windows phone 8.
Thanks
To learn about maps and navigation click here
this is the official document from windows phone dev center. If you are trying to add some UI element to the maps refer this document click here.
This will use a Grid inside a MapOverlay, and works pretty well...
var textGrid = new Grid();
textGrid.ColumnDefinitions.Add(new ColumnDefinition(){Width = GridLength.Auto});
textGrid.Background = new SolidColorBrush(Colors.Black){Opacity = 0.7};
var distText = new TextBlock();
distText.Margin = new Thickness(8,4,8,4);
distText.Text = <your text>;
distText.Foreground = new SolidColorBrush(Colors.White);
textGrid.Children.Add(distText);
var textOverlay = new MapOverlay { Content = textGrid, GeoCoordinate = midwayCoord };
var layer = new MapLayer();
layer.Add(textOverlay);
Map.Layers.Add(layer);
Map.MapElements.Add(line);

Cannot Integrate Microsoft Advertising sdk in windows phone 8

I am not able to integrate the adcontrol in my windows phone 8 app.
In windows phone 8, the microsoft advertising sdk is already provided in the reference and hence have not downloaded the same.
Below is the code snippet I have used:
// Constructor
public MainPage()
{
InitializeComponent();
// ApplicationID = "test_client", AdUnitID = "Image480_80",
AdControl adControl = new AdControl("test_client", // ApplicationID
"Image480_80", // AdUnitID
true); // isAutoRefreshEnabled
// Make the AdControl size large enough that it can contain the image
adControl.Width = 480;
adControl.Height = 80;
Grid grid = (Grid)this.LayoutRoot.Children[1];
grid.Children.Add(adControl);
}
I have also added various capabilities as mentioned in this link:
Windows phone ads not working
But still I am having no luck...At one place I read you need to have internet connection in order for adcontrol to be visible. Is it true?.
Anyways require help on the same.
Thanks In Advance!!!...
Solution:
Issue that I have found in your question is of capabilities, Keep one thing in mind that there is a change in capabilities from windows phone-7 to windows phone-8.
Capabilities that you have added are according to windows phone-7(as you mentioned from link).
You can find required capabilities at: http://msdn.microsoft.com/en-us/library/advertising-mobile-windows-phone-manifest-capabilities(v=msads.20).aspx
Sample:
public MainPage()
{
InitializeComponent();
AdControl adCntrl = new AdControl();
adCntrl.Height = 80;
adCntrl.Width = 480;
adCntrl.ApplicationId = "test_client";
adCntrl.AdUnitId = "Image480_80";
ContentPanel.Children.Add(adCntrl);
}
with Capabilities:
<Capabilities>
<Capability Name="ID_CAP_IDENTITY_USER"/>
<Capability Name="ID_CAP_MEDIALIB_PHOTO"/>
<Capability Name="ID_CAP_NETWORKING"/>
<Capability Name="ID_CAP_PHONEDIALER"/>
<Capability Name="ID_CAP_WEBBROWSERCOMPONENT"/>
<Capability Name="ID_CAP_MEDIALIB_AUDIO"/>
<Capability Name="ID_CAP_MEDIALIB_PLAYBACK"/>
<Capability Name="ID_CAP_SENSORS"/>
</Capabilities>
Assuming that you did all the rest of the requirement stuff correctly and downloaded the Microsoft Ads SDK and added it in to the reference
Top of the main page
using Microsoft.Advertising.Mobile.UI;
In MainPage class initialize these
Grid adGrid = new Grid();
StackPanel adStackPanel = new StackPanel();
AdControl adControl = new AdControl("test_client", "Image480_80", true);
In Constructor do this
adControl.Width = 480;
adControl.Height = 80;
adStackPanel.Children.Insert(0, adControl);
adGrid.Children.Insert(0, adStackPanel);
adGrid.HorizontalAlignment = HorizontalAlignment.Right;
adGrid.VerticalAlignment = VerticalAlignment.Bottom;
this.DrawingSurfaceBackground.Children.Insert(0, adGrid);
//Optional
adControl.ErrorOccurred += adControl_ErrorOccurred;
void adControl_ErrorOccurred(object sender, Microsoft.Advertising.AdErrorEventArgs e)
{
try
{
AdControl ad = (AdControl)sender;
Dispatcher.BeginInvoke(() =>
{
// MessageBox.Show(e.Error.ToString());
Debug.WriteLine(
"error in ad control '" + ad.Name + "': " + e.Error.Message);
Debug.WriteLine("ad control '" + ad.Name + "' visibility = " + ad.Visibility);
});
}
catch (Exception evnt)
{
Debug.WriteLine("oh no! " + evnt.Message);
}
}

How to add tooltip in map windows phone 8?

My windows 8 phone app programatically add an image (as a pin) to a specific coordinataion in map using mapoverlay. And now i would like to add a tooltip to the image (pin) after tapping on it. Does anyone know how to fix this?
pinIMG = new Image();
pinIMG.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("/Assets/pin.png", UriKind.Relative));
MapOverlay myLocationOverlay = new MapOverlay();
myLocationOverlay.Content = pinIMG;
myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
myLocationOverlay.GeoCoordinate = new GeoCoordinate(57.724611, 12.938945);
MapLayer myLocationLayer = new MapLayer();
myLocationLayer.Add(myLocationOverlay);
MyMap.Layers.Add(myLocationLayer);
Instead of adding an Image to the MapOverlay, consider adding an ExpanderView control that expands to add additional data. You'll need to download the Windows Phone Toolkit to get the ExpanderView control. While you're at it you might want to switch over to using Map Extensions Pushpins to get databinding support.
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
MapLayer myLayer = new MapLayer();
MapOverlay myOverlay = new MapOverlay()
{
GeoCoordinate = new GeoCoordinate(-17, 133)
};
ExpanderView expander = new ExpanderView();
expander.Header = new Image()
{
Source = new BitmapImage(new Uri("Assets/ApplicationIcon.png", UriKind.Relative)),
Width = 200
};
expander.ItemsSource = new[]
{
new TextBlock{ Text = "HELLO"}
};
;
myOverlay.Content = expander;
myLayer.Add(myOverlay);
myMap.Layers.Add(myLayer);
}
When we run this sample we can see the following icon over australia:
And once we click ti we can see our "Hello" text show up:
A few ceavets: the code sample above is terrible. ExpanderView is meant to use both ItemSource and IteTemplate for multiple items databinding. Using it for a single item isn't great. The above code sample is also terrible since it creates UI elements in C# code whereas using Map Extensions could have placed this code in XAML.