How to specific Windows 8.1 and Windows Phone 8.1platform in C++/CX - windows-phone-8.1

I have the program in Runtime Component Project (Universal) to get Application ID,
Platform::Guid MyClass::getAppId()
{
#ifdef WINAPI_PARTITION_PHONE_APP
return Windows::ApplicationModel::Store::CurrentApp::AppId;
#endif
}
After that I created a Windows 8.1 Application and call the function, it should get error as I expect windows phone return back data only, however, it past the compilation, and I tried to use other macro from winapifamily.h and all failed.
So, how do I distinguish the target platform for Windows 8.1 and Windows Phone App?

#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
// This code is for Win32 desktop apps
#else
// This code is for WinRT Windows Store apps
#endif
#if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
// This code is for Windows phone 8
#endif
Reference: msdn forum

Related

How to detect that WP8.1 app launched on Windows 10 Mobile?

I need to check OS version (WP 8.1 or W10) in my code of WP8.1 application. What better way to do this? May be reflection or some special API for this purpose?
I didn't find any other way to do this, so here's my approach.
The following property IsWindows10 detects if a Windows 8.1 or Windows Phone 8.1 app is running on a Windows 10 (including Windows 10 Mobile) device.
#region IsWindows10
static bool? _isWindows10;
public static bool IsWindows10 => (_isWindows10 ?? (_isWindows10 = getIsWindows10Sync())).Value;
static bool getIsWindows10Sync()
{
bool hasWindows81Property = typeof(Windows.ApplicationModel.Package).GetRuntimeProperty("DisplayName") != null;
bool hasWindowsPhone81Property = typeof(Windows.Graphics.Display.DisplayInformation).GetRuntimeProperty("RawPixelsPerViewPixel") != null;
bool isWindows10 = hasWindows81Property && hasWindowsPhone81Property;
return isWindows10;
}
#endregion
How does it work?
In Windows 8.1 the Package class has a DisplayName property, which Windows Phone 8.1 doesn't have.
In Windows Phone 8.1 the DisplayInformation class has a RawPixelsPerViewPixel property, which Windows 8.1 doesn't have.
Windows 10 (including Mobile) has both properties. That's how we can detect which OS the app is running on.
Try this System.Environment.OSVersion.Version

How to get the Application Process ID in Windows Phone 8.1 Store Apps

I am developing a Windows Phone 8.1 Application and there is a need to get the Application Process ID from code. Any API with which I can get that?
You can use GetCurrentProcess followed by DuplicateHandle (and later CloseHandle) but I'm curious what you need it for... there's not much you can do with it in a Store app so maybe this won't complete your scenario.
Finally got the solution.
The Dll's for Desktop apps and Phone apps are different though the function names will be same.
When tried to import Kernal.dll lib in WIn Phone 8.1 and used p/invoke code, an exception, DllNotFoundException will be thrown. Instead in Win Phone 8.1 instead use "api-ms-win-core-processthreads-l1-1-1.dll"
To get the process ID in Win Phone 8.1 :
1)Create binding to WIN32 lib:
[DllImport("api-ms-win-core-processthreads-l1-1-1.dll", CharSet = CharSet.Unicode, ExactSpelling = false, PreserveSig = true)]
internal static extern uint GetCurrentProcessId();
2)Call the function:
uint id= GetCurrentProcessId();
For the complete set of Win Phone 8 supported API's see the MSDN link:
https://msdn.microsoft.com/library/windows/apps/jj662956(v=vs.105).aspx#BKMK_ListofsupportedWin32APIs

Create reminder in windows runtime

I am in the process of porting an app from windows phone 8 silverlight to windows phone 8.1 runtime.
Before I could create reminders like this:
Reminder reminder = new Reminder(name);
reminder.Title = titleTextBox.Text;
reminder.Content = contentTextBox.Text;
reminder.BeginTime = beginTime;
reminder.ExpirationTime = expirationTime;
reminder.RecurrenceType = recurrence;
reminder.NavigationUri = navigationUri;
// Register the reminder with the system.
ScheduledActionService.Add(reminder);
How would I do this in windows phone 8.1 runtime?
Thanks,
unfortunately there's no equivalent for Windows phone 8.1 runtime
Migrating your Windows Phone 8 app to a Windows Runtime XAML app
Now you must use toast notifications using the new Action Center feature
MSDN Reference
Action Center QuickStart

Is Worklight App based on Dojo toolkit 1.9 supported in Windows phone 8?

I am working on a worklight App using it's default 1.9 Dojo Toolkit. My App is working fine in Android emulator and in the web browser simulator. I tried to test the same app in Windows phone 8 Emulator but I am not able to see the whole Home page. I can see only Tabbar Button part used at the button while I am not able to see the list items used in the page. My Question is does Dojo Toolkit 1.9 supports Windows Phone 8?
I have visited dojo 1.9 release link and It says that in dojo 1.9, support for Windows Phone 8 has been included. If this is true, What could be the reason of failure for my app in Windows phone 8 emulator?
I also got below log when I created Windows phone 8 environment in my Worklight Project.
[2013-11-12 22:14:08] Environment 'Windows Phone 8' was created.
[2013-11-12 22:14:13] Starting build process: application 'KaiserTestApp', environment 'windowsphone8'
[2013-11-12 22:14:28] Windows Phone 8 app may not work well with Dojo toolkit included for this Application. Use a different Worklight Project, without Dojo toolkit, for Windows Phone 8 apps.
[2013-11-12 22:14:28] Application 'KaiserTestApp' with environment 'windowsphone8' build finished.
There is a WP8 VM bug that might hurt ListItem and might explain your issue. To check if that you are falling into this just monkey patch the _ItemBase _setSelectedAttr method this way and see if that fixes your issue:
_setSelectedAttr: function(/*Boolean*/selected){
// summary:
// Makes this widget in the selected or unselected state.
// description:
// Subclass should override.
// tags:
// private
if(selected){
var p = this.getParent();
if(p && p.selectOne){
// deselect the currently selected item
var arr = array.filter(p.getChildren(), function(w){
return w.selected;
});
array.forEach(arr, function(c){
this._prevSel = c;
c.set("selected", false);
}, this);
}
}
this.selected = selected;
//this._set("selected", selected);
}
If that is fixing your issue let us know and we will see how to release an updated version of Dojo that workarounds that WP8 WM bug.

How to exit or quit my Windows Phone 8 app programmatically?

I am developing a Windows Phone 8 application.
How can I exit or quit programmatically (through code) from my Windows Phone 8 app?
What are the various ways in which I can programmatically (through code) exit or quit from my Windows Phone 8 app?
In WP8 there's a new API which lets you terminate the application:
Application.Current.Terminate();
By calling the method your app will immediatelly terminate. However the Application_Closing event won't be called, and IsolatedStorageSettings.ApplicationSettings dictionary won't be automatically persisted.
So if you have data hanging around in IsolatedStorageSettings.ApplicationSettings that you don't want to lose then it's wise to save it:
IsolatedStorageSettings.ApplicationSettings.Save();
Application.Current.Terminate();
Also the method should not be misused. See http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.application.terminate(v=vs.105).aspx for more info for legitimate use cases.
while (((PhoneApplicationFrame)App.Current.RootVisual).CanGoBack)
{
((PhoneApplicationFrame)App.Current.RootVisual).RemoveBackEntry();
}
In Windows Phone 8.1, the method has been renamed to
Application.Current.Exit();