Adding Windows Phone 8 Tile functionality to Windows Phone OS 7.1 app - windows-phone-7

I'm trying to support the new Windows Phone tile functionality in my existing Windows Phone OS 7.1 application, using the documentation from MSDN. However, I can't seem to create an IconicTile through reflection as it keeps giving me NullReferenceExceptions and AmbiguousMatchExceptions. Here is the code I am using:
public static void CreateIconicTile(Uri tileId, string title, int count, string wideContent1, string wideContent2, string wideContent3, Uri smallIconImage, Uri iconImage, Color backgroundColor)
{
// Get the new IconicTileData type.
Type iconicTileDataType = Type.GetType("Microsoft.Phone.Shell.IconicTileData, Microsoft.Phone");
// Get the ShellTile type so we can call the new version of "Update" that takes the new Tile templates.
Type shellTileType = Type.GetType("Microsoft.Phone.Shell.ShellTile, Microsoft.Phone");
// Get the constructor for the new IconicTileData class and assign it to our variable to hold the Tile properties.
StandardTileData CreateTileData = new StandardTileData();
// Set the properties.
SetProperty(CreateTileData, "Count", count);
SetProperty(CreateTileData, "WideContent1", wideContent1);
SetProperty(CreateTileData, "WideContent2", wideContent2);
SetProperty(CreateTileData, "WideContent3", wideContent3);
SetProperty(CreateTileData, "SmallIconImage", smallIconImage);
SetProperty(CreateTileData, "IconImage", iconImage);
SetProperty(CreateTileData, "BackgroundColor", backgroundColor);
// Invoke the new version of ShellTile.Create.
shellTileType.GetMethod("Create").Invoke(null, new Object[] { tileId, CreateTileData });
}
I also tried creating the tile using the Windows Phone OS 7.1 way (ShellTile.Create(...)) and then calling the UpdateIconicTile method via reflection as described in the MSDN documentation. But that didn't work either.
Any help would be greatly appreciated. Thanks!
EDIT: Just to clarify, I am checking the platform version to ensure this code only runs on Windows Phone 8 devices and I have added the necessary code to my manifest.
RESOLVED: Thanks to the answer given by Martin Suchan below, I was able to solve this problem. The problem was with my call to Invoke(...) missing some properties. Here is the new line I am using to actually create the tile:
shellTileType.GetMethod("Create", new Type[] { typeof(Uri), typeof(ShellTileData), typeof(bool) }).Invoke(null, new Object[] { tileId, CreateTileData, true });

Have you tried the library Mangopollo, that contains working wrapper for creation new tiles in WP7.1 apps when running on WP8?
http://mangopollo.codeplex.com/

You have to make sure that reflection is enabled across the code.
Iconic Tiles are only available for windows phone 8 therefore you can only put the code into a windows phone 7.1 project if you check the version
private static Version TargetedVersion = new Version(8, 0);
public static bool IsTargetedVersion {get{
return Environment.OSVersion.Version >= TargetedVersion;}}
Now see if the bool IsTargetedVersion is true. Basically,
if(IsTargetedVersion){
//iconic tile code
}
Thus only when a windows phone with compatible features (i.e. an wp8) runs your app then it will work.

Related

Properly implement In-App Updates in App Center?

I am reading this documentation/article from Microsoft on how to Distribute Mobile apps with app center. The problem is I really don't understand how to implement this. I have a app on app center (Android) I want to implement mandatory update so that I can eliminate the bugs of the previous version. I tried to distribute the app with mandatory update enabled and it is not working. How can I fix this?
https://learn.microsoft.com/en-us/appcenter/distribution/
Here is what I did I added this code on my App.xaml.cs (XAMARIN FORMS PROJECT):
protected override void OnStart ()
{
AppCenter.Start("android={Secret Code};", typeof(Analytics), typeof(Crashes), typeof(Distribute));
Analytics.SetEnabledAsync(true);
Distribute.SetEnabledAsync(true);
Distribute.ReleaseAvailable = OnReleaseAvailable;
}
bool OnReleaseAvailable(ReleaseDetails releaseDetails)
{
string versionName = releaseDetails.ShortVersion;
string versionCodeOrBuildNumber = releaseDetails.Version;
string releaseNotes = releaseDetails.ReleaseNotes;
Uri releaseNotesUrl = releaseDetails.ReleaseNotesUrl;
var title = "Version " + versionName + " available!";
Task answer;
if (releaseDetails.MandatoryUpdate)
{
answer = Current.MainPage.DisplayAlert(title, releaseNotes, "Download and Install");
}
else
{
answer = Current.MainPage.DisplayAlert(title, releaseNotes, "Download and Install", "Ask Later");
}
answer.ContinueWith((task) =>
{
if (releaseDetails.MandatoryUpdate || (task as Task<bool>).Result)
{
Distribute.NotifyUpdateAction(UpdateAction.Update);
}
else
{
Distribute.NotifyUpdateAction(UpdateAction.Postpone);
}
});
return true;
}
And here is what I added on my MainActivity.cs(ANDROID PROJECT):
AppCenter.Start("{Secret Code}", typeof(Analytics), typeof(Crashes), typeof(Distribute));
Looking at this App Center documentation here for Xamarin Forms -
You can customize the default update dialog's appearance by implementing the ReleaseAvailable callback. You need to register the callback before calling AppCenter.Start
It looks like you need to swap your current ordering to get in-app updates working.
There could be a lot of different reasons as to why they are not working. As you can see in the Notes here and here,
Did your testers download the app from the default browser?
Are cookies enabled for the browser in their settings?
Another important point you'll read in the links, is that the feature is only available for listed distribution group users. It is not for all your members. You could use a simple version checker for your purpose instead or you could use a plugin.

Portable class library object properties cannot be evaluated

I have a problem serializing pcl class object because the class objects property is cannot be evaluated. The structure of my solution is having three projects -
Xamarin.Android, reference Services, and Dto
PCL (for Services), reference Dto (target frameworks: .Net Framework 4.5, ASP.Net Core 1.0, Windows 8, Windows Phone 8.1, Xamarin.Android, Xamarin.iOS, Xamarin.iOS(Classic)
PCL (for Dto)) (target frameworks: .Net Framework 4.5, ASP.Net Core 1.0, Windows 8, Windows Phone 8.1, Xamarin.Android, Xamarin.iOS, Xamarin.iOS(Classic)
I have one method in my service class like -
public async Task<HttpResponseMessage> SignIn(string username, string password)
{
var user = new Dto.UserLogin(username, password);
var serialize = Newtonsoft.Json.JsonConvert.SerializeObject(user);
var content = new StringContent(serialize);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
HttpResponseMessage response = null;
using (var client = GetClient("{urlhere}", username, "POST"))
{
response = await client.PostAsync("api/{methodname}", content);
}
return response;
}
The code above does not throw error and can instantiate the "user" variable. However the problem was that when the serialization line happens, it serialize nothing. It seems like the "user" object is cannot access or show the two properties "Email" and "Password". But I can access them in debug using "user.Email". I've attached a screenshot of it.
Email and Password properties are public.
Thanks,
Marvin
The comment from #Jack helps me to figure out the culprit. In Xamarin.Android property settings->Android options->linker, currently it is set to "SDK and User assemblies". I changed it to "SDK Assemblies Only" and this solved the problem.

Launch Cordova Windows App with Parameters

Am finding hard to launch Cordova Windows App, from another native Windows App.
Using Protocol invocation, I am passing few parameters to Cordova Windows App, to see if the Cordova app identifies those parameters from the Windows Native App.
Is there anyway to pass Parameters from native Windows App to Cordova App, so that Cordova App identifies the parameters as arguments?
In native windows 8 store app I am using app protocol association to send parameters one app to another app. like
in sender app:
mainpage.xaml.cs on button click
var url = "apptest:?" + name;
Uri uri = new Uri(url);
await Launcher.LaunchUriAsync(uri);
in received app
Package.appxmanifest:
Declarations --> available declarations add --> protocol --> name = apptest
app.xaml.cs
protected override void OnActivated(IActivatedEventArgs args)
{
if (args.Kind == ActivationKind.Protocol)
{
ProtocolActivatedEventArgs protocolArgs = args as ProtocolActivatedEventArgs;
var rootFrame = new Frame();
rootFrame.Navigate(typeof(MainPage), protocolArgs);
Window.Current.Content = rootFrame;
}
Window.Current.Activate();
}
mainpage.xaml.cs
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ProtocolActivatedEventArgs pa = e.Parameter as ProtocolActivatedEventArgs;
if(pa != null)enter code here
{
string qS = pa.Uri.Query;
if (!string.IsNullOrEmpty(qS))
{
Txt_name.Text = qS;
}
}
}
in this way i will take the data from sender app.
Same like is there any way to receive data from windows 10 native app to cordova app. it is very hard to find the solution. not able to find the exact piece of code.

Geofence is not being triggered in the background in windows phone 8.1

I'm trying to implement geofencing in Windows phone 8.1. First I wanted to create a sample Project to understand how it Works, but i couldnt make it works. What I'm trying to achieve is basically, I'll set the coordinates and close the app by pressing back button and it will trigger a toast notification when the phone is in the area of interest.
I've created a blank Windows phone(silverlight) 8.1 Project(geofence_test_01) and added a Windows RT Component Project(BackgroundTask) into the same solution. Added a reference for BackgroundTask in the geofence_test_01 Project.
ID_CAP_LOCATION is enabled in the app manifest.
MainPage.xaml has only one button to start geofencing.
<Button Name="btnStart" Content="Start" Click="btnStart_Click"/>
In btnSave_Click, I call a method which creates the geofence and registers the background task.
private void btnStart_Click(object sender, RoutedEventArgs e)
{
Init_BackgroundGeofence();
registerBackgroundTask();
}
private async Task Init_BackgroundGeofence()
{
//----------------- Crating Geofence ---------------
var geofenceMonitor = GeofenceMonitor.Current;
var geoId = "building9";
var positionBuilding9 = new BasicGeoposition()
{
Latitude = 47.6397,
Longitude = -122.1289
};
var geofence = new Geofence(geoId, new Geocircle(positionBuilding9, 100),
MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited,
false, TimeSpan.FromSeconds(10));
geofenceMonitor.Geofences.Add(geofence);
}
private async Task registerBackgroundTask()
{
//----------------- Register Background Task ---------------
var backgroundAccessStatus =
await BackgroundExecutionManager.RequestAccessAsync();
var geofenceTaskBuilder = new BackgroundTaskBuilder
{
Name = "GeofenceBackgroundTask",
TaskEntryPoint = "BackgroundTask.GeofenceBackgroundTask"
};
var trigger = new LocationTrigger(LocationTriggerType.Geofence);
geofenceTaskBuilder.SetTrigger(trigger);
var geofenceTask = geofenceTaskBuilder.Register();
}
And finally, in BackgroundTask, I've the following code:
namespace BackgroundTask
{
public sealed class GeofenceBackGroundTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
var geofenceMonitor = GeofenceMonitor.Current;
var geoReports = geofenceMonitor.ReadReports();
var geoId = "building9";
foreach (var geofenceStateChangeReport in geoReports)
{
var id = geofenceStateChangeReport.Geofence.Id;
var newState = geofenceStateChangeReport.NewState;
if (id == geoId && newState == GeofenceState.Entered)
{
//------ Call NotifyUser method when Entered -------
notifyUser();
}
}
}
private void notifyUser()
{
var toastTemplate = ToastTemplateType.ToastText02;
var toastXML = ToastNotificationManager.GetTemplateContent(toastTemplate);
var textElements = toastXML.GetElementsByTagName("text");
textElements[0].AppendChild(toastXML.CreateTextNode("You are in!"));
var toast = new ToastNotification(toastXML);
ToastNotificationManager.CreateToastNotifier().Show(toast);
}
}
}
I get no error when building and deploying this in the emulator. I set a breakpoint in the backgroundTask but I've not seen that part of code is called yet. It never hits the breakpoint. I test it by using Additional Tools of the emulator, in Location tab, by clicking somewhere in my geofence area on the map, waiting for a while, but it never hits the breakpoint. Hope somebody can tell me what i am missing here...
I've checked these following links to build this application:
http://www.jayway.com/2014/04/22/windows-phone-8-1-for-developers-geolocation-and-geofencing/
Geofence in the Background Windows Phone 8.1 (WinRT)
Toast notification & Geofence Windows Phone 8.1
http://java.dzone.com/articles/geofencing-windows-phone-81
Thanks
You can download the project here:
https://drive.google.com/file/d/0B8Q_biJCWl4-QndYczR0cjNhNlE/view?usp=sharing
---- Some clues
Thanks to Romasz, I've checked the Lifecycle events and i see "no background tasks" even after registerBackgroundTask() is executed.... Apparently there is something wrong/missing in registerBackgroundTask() method.
I've tried to build my sample (it was easier for me to build a new one) basing on your code and it seems to be working. You can take a look at it at my GitHub.
There are couple of things that may have gone wrong in your case:
remember to add capabilities in WMAppManifest file (IS_CAP_LOCATION) and Package.appxmanifest (Location)
check the names (of namespaces, classes and so on) in BackgroundTask
check if your BackgroundTask project is Windows Runtime Componenet and is added to your main project as a reference
I know you have done some of this things already, but take a look at my sample, try to run it and maybe try to build your own from the very beginning.
Did you add your background task in the Package.appxmanifest under Declarations with the correct supported task types (Namely Location)?

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?
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)
Have you tried a flip tile and the using something like this:
http://blog.ecofic.com/?p=406
Write the number to isolated storage then when they click the tile you read the isolated storage and call the number.
You can also use the Mangopollo library from CodePlex to create a secondary live tile: http://mangopollo.codeplex.com/

Resources