How to check/switch the airplane mode programmatically in Windows 8? - winapi

I have to check if the Airplane Mode is enabled in Windows 8 and maybe switch its state. I am currently working on a C# .NET 4.0 Windows Forms application but the answers in this question shouldn't be limited by that.

Unfortunately, there isn't a programmatic way for Metro apps to change the airplane mode in Windows 8. It is against the Metro guidelines for an application to go outside its sandbox and modify system settings like this without user permission (see the discussion at http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/1ad10725-b1b8-4723-b2c3-861900809e02).
Now, you may be able to figure out the status by using some of the functionality in the Windows.Networking.NetworkOperators namespace. Specifically, check out the MobileBroadbandRadioState and NetworkDeviceStatus enumerations.
Or, you could prompt the user to make the change by explaining how to access the setting using Windows Key + I, Change PC Settings, Wireless, Airplane Mode.

Here is a code snippet to get the NetworkConnectivityLevel which will likely give you what you need to know. I don't know if there is a way to change it. I would doubt it because you would need to also provide a way to pick a network to connect to.
public static NetworkConnectivityLevel GetNetworkConnectivityLevel()
{
ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();
var ncl = NetworkConnectivityLevel.None;
if (profile != null)
{
ncl = profile.GetNetworkConnectivityLevel();
}
return ncl;
}

Related

Windows Phone 8 maps uri scheme

I'm developing a windows phone app and want to show the maps app. I know about the uri scheme's ms-drive-to, ms-walk-to and the HERE equivalents, but I don't want navigation. I also don't want to rely on HERE maps, because someone might not have installed that one. The question:
Is there a way of opening the default Map app on windows phone 8?
You could use the MapsTask API;
MapsTask mapsTask = new MapsTask();
//Omit the Center property to use the user's current location.
//mapsTask.Center = new GeoCoordinate(47.6204, -122.3493);
mapsTask.ZoomLevel = 2;
mapsTask.Show();
You should check the sdk.
If you really want to open the apps, you can do it with a trick. Add a brower task an follow steps of this article.

How to enable Pseudo-language on Windows Phone 8 emulator

I can't seem to enable Pseudo-language on the WP8 emulator. Most tutorials suggest to set the localization via the development operating system, and that these settings somehow "trickle down" into the emulator, but this doesn't seem to work for me -- the emulator just defaults to English no matter how I have my OS language/keyboard set (Control Panel -> Language -> Move Up <language> to top -> restart emulator).
I can change localization settings within the phone's "Settings", and although other languages successfully translate within my app, Pseudo is not an option.
I have Googled lots of MSDN information (including documentation on how to troubleshoot this specific issue) and I have seemingly exhausted my options.
tl;dr Has anyone had trouble with the "trickle down" of localization settings into the Windows Phone emulator? How do you fix it?
Here is the solution recommended by Microsoft
Thread.CurrentThread.CurrentCulture = new CultureInfo("qps-ploc");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("qps-ploc");
See http://msdn.microsoft.com/en-us/library/windows/apps/jj569303.aspx
When I want to run my WP8 app in pseudo-loc, I add the following line to the beginning of App constructor:
Thread.CurrentThread.CurrentUICulture = new CultureInfo("qps-ploc");

Can I run my winRT application as a screensaver?

Is there a way to make my winRT application as a screen saver in xaml?
As Jerry says, there's no straightforward way to make a Windows Store app screensaver. However, there's a roundabout solution that might work for you on Windows 8, but not Windows RT. I have it nearly working. I'll share what I have so far.
A screensaver is just an executable with a .scr extension that's kept in C:\Windows\System32. For example, look at C:\Windows\System32\Bubbles.scr. The solution I have in mind is to create a .scr screensaver whose only purpose is to launch your Windows Store application, which you say will use XAML.
You can't launch a Windows Store app from the command line directly, so you'll create a launcher app. Take a look at a blog post called Automating the testing of Windows 8 apps by Ashwin Needamangala. Partway down the article, look for the section called Automating the activation of your app. It contains a sample C++ application which can launch Windows Store apps in the following way:
C:>Win8AppLaunch.exe Microsoft.BingNews_8wekyb3d8bbwe!AppexNews
The sample launcher on that page needs to be modified, but before you do that just copy the code into a C++ console app:
You're almost ready to test it out from the command line, but you need to specify the name of the app as an AppUserModelId. The details are in Ashwin's post, but to paraphrase you first want to allow the execution of PowerShell scripts on your system with:
PS C:> Set-ExecutionPolicy AllSigned
Then run this PowerShell script:
$installedapps = get-AppxPackage
foreach ($app in $installedapps)
{
foreach ($id in (Get-AppxPackageManifest $app).package.applications.application.id)
{
$app.packagefamilyname + "!" + $id
}
}
You might like running it in the Windows PowerShell ISE. It's pretty slick. Find the AppUserModelId of your app and then test Win8AppLaunch.exe from the command line, as shown above. This should launch your Windows Store app from command line.
Next, modify the C++ launcher to hard-code the AppUserModelId of your application instead of parsing it from a command line argument. I created a Gist of this. The important part is the line where I declare myApp.
Build the new executable, rename it MyScreenSaver.scr and put it in C:\Windows\System32. It will then appear in the Screen Saver Settings Control Panel. You can preview the screensaver there, and it works. However, if you wait for the screensaver to launch, it will briefly bring up a console window and never fully launch. I'm not sure why. I tried disabling the creation of the console window by switching the project to a Windows app, but that didn't help. You can try that yourself by changing Properties | Configuration | Linker | System | SubSystem to WINDOWS. It's a little more involved, as you'll also need to change the entry point from _tMain to _tWinMain. Contact me through my blog if you want the details. My StackOverflow profile lists it.
At this point it's almost fully working. You might try starting with a blank C++ screensaver that you know works, and then copy in the above code. If I get more time, maybe I'll try this myself.
Cool idea. But, no.
If you want your application to really do something for Windows other than run as a simple app, then you write an extension app. Here's the official word:
Extensions An extension is like an agreement between an app and Windows. Extensions lets app developers extend or customize standard Windows features primarily for use in their apps and potentially for use in other apps.
There are these types of extension apps right now:
Account picture provider (extension)
When users decide to change their account picture, they can either select an existing picture or use an app to take a new one. If your app can take pictures, you can use this extension to have Windows list your app in the Account Picture Settings control panel. From there, users can select it to create a new account picture. For more info about this extension, see the UserInformation reference topic. You can also check out our Account picture name sample.
AutoPlay (extension)
When the user connects a device to a computer, Windows fires an AutoPlay event. This extension enables your app to be listed as an AutoPlay choice for the one or more AutoPlay events.
Background tasks (extension)
Apps can use background tasks to run app code even when the app is suspended. Background tasks are intended for small work items that require no interaction with the user.
Camera settings (extension)
Your app can provide a custom user interface for selecting camera options and choosing effects when a camera is used to capture photos or video. For more info about this extension, see Developing Windows Store device apps for cameras.
Contact picker (extension)
This extension enables your app to register to provide contact data. Your app is included in the list of apps that Windows displays whenever the user needs access to their contacts.
For more info about this extension, see the Windows.ApplicationModel.Contacts.Provider reference topic. You can also check out Managing user contacts.
File activation (extension)
Files that have the same file name extension are of the same file type. Your app can use existing, well known file types, such as .txt, or create a new file type. The file activation extension enables you to define a new file type or register to handle a file type.
Game Explorer (extension)
Your app can register with Windows as a game. To do this, you must create a Game Definition File (GDF), build it as a binary resource in your app, and declare that resource in the package manifest.
Print task settings (extension)
You can design an app that displays a custom print-related user interface and communicates directly with a print device. When you highlight the features that are specific to a particular make and model of print device, you can provide a richer, more enhanced user experience.
Protocol activation (extension)
Your app can use existing protocols for communication, such as mailto, or create a custom protocol. The protocol activation extension enables you to define a custom protocol or register to handle an existing protocol.
SSL/certificates (extension)
Digital certificates are used to authenticate one entity to another. For example, certificates are often used to authenticate a user to web services over SSL. This extension enables you to install a digital certificate with your app.
cite: http://msdn.microsoft.com/en-us/library/windows/apps/hh464906.aspx
Unfortunately, nothing has to do with screen savers. The technical reason, at this time, you cannot write a Windows 8 app that functions as a screensaver is because Windows 8 apps are fundamentally tied to run inside the WinRT execution environment. That shell does not extend out past the Start menu in this current version of Windows. So, there's no way to execute outside - like as a screen saver. Screen savers are still built the "old fashion way".

How can I test my WP7 app under no Internet connection conditions in emulator?

I am developing a Windows Phone 7 App which is capable to work without internet connection but optionally loads some content from web if network is available.
How can I test this application in Phone Emulator under the condition of having no internet connection?
There is a Settions option available in the main menu, but unlike on real device there is no option to disable data connection. The only solution I came up with is to disable the WiFi adaptor of my development laptop, but this seems to be an ultimate option.
Is there any way to force emulator to run in disconnected environment?
Another option is to use NetLimiter
Not only can you shut off connection to your app, you can change the speeds to simulate a poor connection and see how your app behaves. NetLimiter and Fiddler are sweet tools.
Like you said, I just disconnect my development computer from the internet whenever I want to test a wp7 app under no internet connection. You can't force it from the emulator, but you could probably turn it off using code, but that seems like too much work to me.
Another StackOverflow post.
From WP7 App Hub.
Check out this question. It has some info on the same problem. Also check out this post.
You can use this method in your code for detecting internet connection. If you put it in a static class as a static method, it works nice.
private bool InternetIsAvailable()
{
var available = !NetworkInterface.GetIsNetworkAvailable();
#if DEBUG
available = false;
#endif
if (!available)
{
MessageBox.Show("No internet connection is available. Try again later.");
return false;
}
return true;
}
There is an easy way...
If your app do not require a online login... Desktop, open the "Internet Explorer" > "Settings" > "Connection" and setup a proxy which is of course not valid. Save the changes. Now, you should not be able to browse a website anymore. After these steps, start the simulator...

Switching flight mode programmatically

Is there any way switch on/off flight mode programmatically in Windows Phone 7.5. What I want to do is create background task which will be check time and switch on/off flight mode.
Thanks in advance.
No, this functionality is not available.
It was a design principle behind the platform that applications should not be able to do things without the user knowing it.
If such functionality was available then it would be possible for an app (either deliberately or accidentally-though a bug) to get the devices state in a setting other than what they user may expect. In such a scenario users will typically blaim the phone/platform for what has happened, not a misbehaving application.
Though you cannot programatically do it (as others have mentioned), you can send the user directly to the proper page in the settings panel and allow them to do it. Here's an example of using the ConnectionsSettingsTask:
http://msdn.microsoft.com/en-us/library/hh394011(v=VS.92).aspx
You would want to set the ConnectionSettingsType property:
http://msdn.microsoft.com/en-us/library/microsoft.phone.tasks.connectionsettingstask.connectionsettingstype(v=VS.92).aspx
To 'AirplaneMode'.

Resources