How to setup project for Monogame + Windows 8.1? - windows-phone-8

I'm in the middle of app development with Monogame, and I wanted to add a project for Windows Phone. I have a device with Windows Mobile 8.1 for testing, and I'm using Monogame 3.5 (latest) + VS 2015. But how do I create a project?
The templates for Monogame have several platforms, but the only one for Windows Mobile seems to be Windows 10 Uniwersal Project (UWP). I doubt this would run on WM8.1. Or would it? If not, how do I create the project this otherwise?
Update:
Did more research on this and it seems you need to have minimum Windows 8.1 on your dev PC to develop for Windows Phone 8.1:
https://www.visualstudio.com/en-us/products/visual-studio-2015-compatibility-vs.aspx
So I guess I will just support Android and iOS like all other mobile apps.

Variant 1:
Create win phone 8.1 project
Add NuGet package MonoGame.Framework.WindowsPhone81 (NuGet)
Add standart Game1.cs source code file from Monogame templates
Add in MainPage.xaml.cs
using MonoGame.Framework;
Change in MainPage.xaml.cs
public sealed partial class MainPage : SwapChainBackgroundPanel
{
readonly Game1 _game;
public MainPage(string launchArguments)
{
this.InitializeComponent();
_game = XamlGame<Game1>.Create(launchArguments, Window.Current.CoreWindow, this);
}
}
Change MainPage.xaml (MyGame - default project namespace)
<SwapChainBackgroundPanel
x:Class="MyGame.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyGame"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid >
</Grid>
</SwapChainBackgroundPanel>
Change App class in App.xaml.cs
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
var gamePage = Window.Current.Content as MainPage;
if (gamePage == null)
{
gamePage = new MainPage(args.Arguments);
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
}
Window.Current.Content = gamePage;
}
Window.Current.Activate();
}
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
deferral.Complete();
}
Add Content.mgcb
Add monogameplatform to project file (.csproj) into PropertyGroup section
<PropertyGroup>
...
<MonoGamePlatform>WindowsStoreApp</MonoGamePlatform>
<MonoGameContentBuilderExe>
</MonoGameContentBuilderExe>
...
</PropertyGroup>
Add next line to project file (.csproj) into Project section
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
Variant 2: use tool from Protobuild.org

Related

How to launch app from another app in Windows Phone 8.1

I want to launch my app from another app in the Windows Phone 8.1 environment. I followed the instructions in MSDN, but I cannot figure out how to call the first app from the second. This is the protocol I added in the first app's manifest file:
<Extensions>
<Extension Category="windows.protocol">
<Protocol Name="myapp">
<Logo>Assets\SmallLogo.scale-240.png</Logo>
<DisplayName>my App 1</DisplayName>
</Protocol>
</Extension>
</Extensions>
This is my call from the second app, that does absolutely nothing:
private async void btn_Click(object sender, RoutedEventArgs e)
{
await Windows.System.Launcher.LaunchUriAsync(new System.Uri("myapp:"));
}
Follow the steps in Auto-launching apps using file and URI associations for Windows Phone 8
And you have use use a class which is derived from UriMapperBase to handle the navigation and have to set it as RootFrame.UriMapper in the App.xaml.cs
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
// Create the frame but don't set it as RootVisual yet; this allows the splash
// screen to remain active until the application is ready to render.
RootFrame = new PhoneApplicationFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
// Assign the URI-mapper class to the application frame.
RootFrame.UriMapper = new AssociationUriMapper();
******
}

How to collect application logs in windows phone 8.1?

I am new to windows phone platform.Is there anything available like logcat in android for windows for collecting logs?Thanks in advance.
Windows 8.1 introduced new classes to simplify logging. These classes are LoggingChannel, LoggingSession and others.
Here's an example:
App.xaml.cs
LoggingSession logSession;
LoggingChannel logChannel;
public App()
{
this.InitializeComponent();
this.UnhandledException += App_UnhandledException;
}
void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
logChannel.LogMessage("Unhandled exception: " + e.Message);
logSession.SaveToFileAsync(Windows.Storage.ApplicationData.Current.LocalFolder, "MainLog.log").AsTask().Wait();
}
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
logSession = new LoggingSession("MainLogSession");
Resources["MainLogSession"] = logSession;
logChannel = new LoggingChannel("AppLogChannel");
logSession.AddLoggingChannel(logChannel);
}
MainPage.xaml.cs
LoggingChannel logChannel;
public MainPage()
{
this.InitializeComponent();
var logSession = (LoggingSession)Application.Current.Resources["MainLogSession"];
logChannel = new LoggingChannel("MainPageLogChannel");
logSession.AddLoggingChannel(logChannel);
logChannel.LogMessage("MainPage ctor", LoggingLevel.Information);
}
I highly recommend watching the Making your Windows Store Apps More Reliable keynote during the 2013 build conference, where Harry Pierson demonstrates these new APIs in more detail (including uploading the log file to a backend server using a background task that gets executed when the phone is connected to AC power).
You can use System.Diagnostics.Debug to view the logs on Visual Studio Console Window but you won't be able to collect them later because it's only shown during debug.
I recommend the use of MetroLog, a lightweight logging system designed specifically for Windows Store and Windows Phone apps.
You can install it using NuGet
Install-Package MetroLog
Here's an quick example:
using MetroLog;
using MetroLog.Targets;
LogManagerFactory.DefaultConfiguration.AddTarget(LogLevel.Trace, LogLevel.Fatal, new FileStreamingTarget());
GlobalCrashHandler.Configure();
ILogger log = LogManagerFactory.DefaultLogManager.GetLogger<MainPage>();
log.Trace("This is a trace message.");
You can find a tutorial explaining how to add it on your project at http://talkitbr.com/2015/06/11/adicionando-logs-em-universal-apps. Also there is an explanation regarding retrieving these logs.

Application working on emulator but crashed on phone WP8

At start I'm sorry for my English is poor. And this is the only place where i solved the problem.
I have a problem with my application. I write and test it on emulator in VisualStudnio 2012 and It work fine. But when I add aplication in WindowsPhone store and I get to phone. It crashed. I think that problem is in geolocator or something with GPS, because when i use function where my it don't use gps it work. Everywhere where i use geolocator_geopositionchanged it break down and app is terminate. in one of application page i use map control but i gave token and application id but only in class where i use map.
private void maping_Loaded(object sender, RoutedEventArgs e)
{
Microsoft.Phone.Maps.MapsSettings.ApplicationContext.ApplicationId = "id";
Microsoft.Phone.Maps.MapsSettings.ApplicationContext.AuthenticationToken = "token";
}
Do you have any sugestion or advices?
if you want watching app there is a link
http://www.windowsphone.com/pl-PL/store/app/opencaching/06bce1e1-16ef-4ebf-ac53-23b4c725f78b
I have geolocator in a few class it's one of them
Geolocator code
if (!tracking)
{
gps = new Geolocator();
gps.DesiredAccuracy = PositionAccuracy.High;
gps.ReportInterval = 100;
gps.PositionChanged += geolocator_PositionChanged;
}
else
{
gps.PositionChanged -= geolocator_PositionChanged;
gps = null;
}
tracking = !tracking;
Geoposition changed code
void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
double distance = 0;
distance = point.GetDistanceTo(new GeoCoordinate(args.Position.Coordinate.Latitude, args.Position.Coordinate.Longitude));
string asa = Convert.ToInt64(distance).ToString();
if (asa != null)
{
Dispatcher.BeginInvoke(() =>
{
TBodleglosc.Text = asa +"m";
navi.Rotation = 180 + Kierunek(point.Latitude, point.Longitude, args.Position.Coordinate.Latitude, args.Position.Coordinate.Longitude);
});
}
}
Debug on your device. If that cannot repro, setup a Beta Test app and use that to distribute the app back to yourself for debugging. Sometimes signing breaks things.
I debug at lumia 920 and I have a problem with convert.toDouble
because there are was , i have . and vice versa
I think that it's connected with phone language
because in english emulator and Ertay Shashko phone who debug it yesterday it's working fine.
At now application work at phone but doesn't at emulator.
but if i change settings on location and language apps work but I can't debug because visual studio have error
It's weird .....

Microsoft.Smartdevice.Connectivity and Windows Phone 8, launch native apps, send input?

I've written a small .NET Console program that will launch the Windows 8 Simulator. Very straightforward:
using Microsoft.SmartDevice.Connectivity;
using Microsoft.SmartDevice.Connectivity.Interface;
using Microsoft.SmartDevice.MultiTargeting.Connectivity;
MultiTargetingConnectivity connectivity = new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID);
var devices = connectivity.GetConnectableDevices();
ConnectableDevice connectableDevice = devices[2];
Console.WriteLine("Found Connectable Device \'" + connectableDevice.Name + "\' for Device id {" + connectableDevice.Id + "}.");
Pretty straightforward. However, what I want to do now is programmatically interact with the device. I know I can launch my own Apps by using iDevice.installApplication but what I really want to do is run a built-in app that comes with the simulator (the mail app). Can I use the SmartDevice.Connectivity libs to send touches, or launch 'hidden' apps that don't show up in the GetInstalledApplications() method? the API is sparse, and doesn't seem like a ton of developers are using this.
I've actually found a better framework than the SmartDevice framework. Inside the C:\Program Files (x86)\Microsoft XDE\8.0 folder you can find the Microsoft.XDE DLLs, which help power the Windows 8 simulator wrapper/skin, and are managed libraries that allow you to interact with the simulator. Sample code:
private static void BootViaXdeLibs()
{
var factory = new Microsoft.Xde.Wmi.XdeWmiFactory();
Console.WriteLine("Polling for virtual machines");
var virtualMachine = factory.GetAllXdeVirtualMachines(SettingsOptions.None)[2];
Console.WriteLine("Found machine {0}", virtualMachine.Name);
if (virtualMachine.EnabledState != VirtualMachineEnabledState.Disabled)
{
Console.WriteLine("Virtual Machine {0} is already running. Shutting down. ", virtualMachine.Name);
virtualMachine.Stop();
while (virtualMachine.EnabledState != VirtualMachineEnabledState.Disabled)
{
Thread.Sleep(1000);
}
}
Console.WriteLine("Starting {0}", virtualMachine.Name);
virtualMachine.Start();
while (virtualMachine.EnabledState == VirtualMachineEnabledState.Starting)
{
Thread.Sleep(1000);
}
Console.WriteLine("Sleeping before image capture to give boot time");
Thread.Sleep(30000);
//Click on the screen
virtualMachine.SendMouseEvent(new MouseEventArgs(MouseButtons.Left, 1, 295, 260, 0));
Thread.Sleep(100);
virtualMachine.SendMouseEvent(new MouseEventArgs(MouseButtons.None, 0, 295, 260, 0));
Thread.Sleep(1000);
Console.WriteLine("Saving screenshot");
//Capture Screen
var res = virtualMachine.GetCurrentResolution();
var image = virtualMachine.GetScreenShot(0, 0, res.Width, res.Height);
image.Save("C:\\image.png", ImageFormat.Png);
virtualMachine.Stop();
}

AIR Application not updating using ApplicationUpdaterUI

I am working in Flex 4.6 AIR application. There is a button when i click on it, It downloads the new version of the application from the server and installed it automatically when AdobeAIRInstaller version 3.8 already installed in my system (both windows and MAC).
When i update the Adobe AIR version from 3.8 to 3.9. the installation process working fine in windows pc but in mac when i click to update, it downloads the application from the server but not installed it automatically.
My Code of XML file is
<?xml version="1.0" encoding="utf-8"?>
<update xmlns="http://ns.adobe.com/air/framework/update/description/2.5">
<versionNumber>1.2.9</versionNumber>
<url>File Path URL</url>
<description><![CDATA[
1. Test swf file secure.
]]></description>
</update>
And the code for update is following
protected function btnUpdate_clickHandler(event:MouseEvent):void
{
NativeApplication.nativeApplication.addEventListener( Event.EXITING,
function(e:Event):void
{
var opened:Array = NativeApplication.nativeApplication.openedWindows;
for (var i:int = 0; i < opened.length; i ++)
{
opened[i].close();
}
});
appUpdater = new ApplicationUpdaterUI();
// Configuration stuff - see update framework docs for more details
appUpdater.updateURL = modellocator.appUpdateURL; // Server-side XML file describing update
appUpdater.isCheckForUpdateVisible = false; // We won't ask permission to check for an update
appUpdater.addEventListener(UpdateEvent.INITIALIZED, onUpdate); // Once initialized, run onUpdate
appUpdater.addEventListener(StatusUpdateErrorEvent.UPDATE_ERROR, onStatusUpdateError);
appUpdater.addEventListener(StatusUpdateEvent.UPDATE_STATUS, onStatusUpdate);
appUpdater.addEventListener(ErrorEvent.ERROR, onError); // If something goes wrong, run onError
appUpdater.initialize(); // Initialize the update framework
}
private function onStatusUpdate(event:StatusUpdateEvent):void
{
trace("Update Status");
}
private function onUpdate(event:UpdateEvent):void
{
appUpdater.checkNow(); // Go check for an update now
}
private function onStatusUpdateError(evt:StatusUpdateErrorEvent):void
{
showAlertMessage(resourceManager.getString('languages','msgInternetNotConnected'), "", "", 286, 142);
modellocator.timerClosePop = new Timer(5000);
modellocator.timerClosePop.addEventListener(TimerEvent.TIMER, removeErrorMessage);
modellocator.timerClosePop.start();
}
private function removeErrorMessage(event:TimerEvent):void
{
PopUpManager.removePopUp(messageAlertPopup);
modellocator.timerClosePop.stop();
}
private function onError(event:ErrorEvent):void
{
trace(event.toString());
}
Please anyone tell me why this is behaving just like that.
Just proceeding with an update to the latest version of Adobe Air (>= 3.9.0.1210) is fixing the ApplicationUpdaterUI() problem in Mac OS X.