What is the MvvmCross version of DeviceNetworkInformation.IsNetworkAvailable - mvvmcross

I'm re-writing a Windows Phone app to make it cross platform using the excellent MvvmCross framework.
On Windows Phone I usually test DeviceNetworkInformation.IsNetworkAvailable to ensure I have a network connection before calling a REST service.
Is there a way of doing this in a cross-platform way using MvvmCross?

There is a cross-platform plugin Cirrious.MvvmCross.Plugins.Network specifically for Network functionality and this was originally built specifically to provide Reachability
However, sadly the WindowsPhone part of this isn't yet implemented! See https://github.com/MvvmCross/MvvmCross/blob/v3.1/Plugins/Cirrious/Network/Cirrious.MvvmCross.Plugins.Network.Phone/Plugin.cs
If you need Reachability within a cross-platform app including WindowsPhone, I'd probably opt for adding this Network plugin, and then also modifying your WindowsPhone Setup to register something like:
public class MyReachability : IMvxReachability
{
public bool IsHostReachable(string host)
return // something using DeviceNetworkInformation.IsNetworkAvailable
}
}
// registered in Setup using:
protected override void InitializeLastChance() {
base.InitializeLastChance();
Mvx.RegisterType<IMvxReachability, MyReachability>();
}
Longer term, I'd be happy to see a decent implementation pushed back into the MvvmCross repository.
Also linking this question to: MvvmCross Reachability on Windows Phone and Network state with mvvmcross?

Related

How to navigate between pages in windows universal app using C++/CX

I am new to Windows universal app development. As per my knowledge Windows universal app can be made by using C++/CX , C# or JavaScript. But Microsoft force to do development by using C++/CX because it uses power of winRT much better than others. So i tried the development using C++/CX for Visual Studio 2015.
I come to a topic of Navigation. To perform navigation in app there is one API
this->Frame->Navigate(TypeName(MySecondPage::typeid)). This API gives me a exception at runtime.
This is the detail scenario what i did.
1. I create project by named NavigationSample using C++/CX.
Then i added new Basic Page of xaml for my Second view/ui and named it as MySecondPage.xaml
Now on first page i.e. MainPage.xaml i added One button.
On event of this button , lets say button_Click as event handler i wrote
this->Frame->Navigate(TypeName(MySecondPage::typeid))
Here is the detailed code:
void NavigationSample::MainPage::button_Click(**Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)**
{
this->Frame->Navigate(TypeName(MySecondPage::typeid));
}
This compile and build fine. But gives exception at runtime. (Same scenario works very fine with C#)
So guys please help me how to resolve this issue?
Thanks
Here's a clue:
m_ptrSettingsPage->Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler([this]() {
m_ptrSettingsPage->Frame->Navigate(Windows::UI::Xaml::Interop::TypeName(AnnuitiesPage::typeid));
}));
Best wait for C++/wimRT

How to implement MVVM in Windows Phone 8.1 app (xaml)?

Could anyone give an example of implementation? Is it done with ViewModel implementing INotifyPropertyChanged (and raising events, as it's done in Silverlight) or some other way? How is ViewModel bound to the view?
All examples I've found so far are incomplete or outdated (refer to Silverlight apps, not Xaml ones).
In the case of Windows RT I would advise to look towards PRISM. It provides really good modern development practices. You will get suitable navigation service, app lifecycle management, great MVVM support and very flexible view and ViewModels resolution mechanism.
You can easily add it to your project via NuGet.
It has pretty good documentation, so if you have any questions you can find an answer on MSDN or even download free book Prism for the Windows Runtime. Our team has successful experience in building projects using PRISM.
I currently use the following approach in my own Universal/W8.1/WP8.1 apps. This approach uses the RArcher WinRT Toolkit, which is an experimental toolkit based on the MVVM pattern.
It provides a way to maintain app state and you can use the ViewModelBase to implement INPC.
It also uses the Unity dependency injection container.
I'd start with making the ViewModelLocator an application-wide resource, so my Views can access it easily.
<Application.Resources>
<vm:ViewModelLocator x:Key="ViewModelLocator" />
</Application.Resources>
The view can use it like so:
<Page.DataContext>
<Binding Source="{StaticResource ViewModelLocator}" Path="MainViewModel" />
</Page.DataContext>
The ViewModelLocator looks like this:
public sealed class ViewModelLocator
{
public ViewModelLocator()
{
RegisterIoCBindings();
}
public IMainViewModel MainViewModel
{
get { return IocContainer.Get<IMainViewModel>(); }
}
private void RegisterIoCBindings()
{
IocContainer.Container.RegisterType(typeof(IMainViewModel), typeof(MainViewModel),
null, new ContainerControlledLifetimeManager());
}
}
The MainViewModel has the ViewModelBase as baseclass and implements the IMainViewModel:
public sealed class MainViewModel : ViewModelBase, IMainViewModel
{
private string myText;
[AutoState]
public string MyText
{
get { return myText; }
set
{
myText = value;
OnPropertyChanged();
}
}
public MainViewModel() // You can use constructor injection here
{
}
}
That is the basic setup. And as the others have stated, MVVM is a pattern and there a many ways to use it. I would say, use what feels good ;-)
If you like to know more about this approach, check out the toolkit and unity DI.
There is no difference, it's the same. Because MVVM is a pattern. You can implement it to your windows phone app easily. I'm using MVVM Light for my wp apps and EventToCommand behavior to raise events. I have an app open sourced on GitHub, you can check it out if you want.

How to use background media player in Windows Phone Silverlight 8.1

I am working on a Windows Phone application for Windows 8.1. I need to use features like Motion classes, Isolated Storage etc. As these features were not supported in Windows Phone 8.1 I went for Windows Phone Silverlight 8.1. Now I have to use BackgroundMediaPlayer in my project and Windows.Media.Playback is not supported in Windows Phone Silverlight 8.1. Is there any possible way by which i can use all the basic API's like:-
-Microsoft.Devices.Sensors
-Microsoft.Xna.Framework
-System.IO.IsolatedStorage-System.Windows.Media.Imaging
and use BackgroundMediaPlayer, Motion classes?? any help will be really useful.
Thanks,
Ekta
Playing Background audio differs in Windows Runtime and Silverlight (Overview). You were trying to use MediaPlayer which:
Minimum supported phone Windows Phone 8.1 [Windows Runtime apps only]
is only for runtime.
As for working with BackgroundAudioPlayer Class in Silverlight 8.1, there is a problem - it won't work. This is a limitation in Silverlight 8.1:
The AudioPlayerAgent and AudioStreamingAgent classes, which supported background audio playback for Windows Phone 8 apps, are not supported in Silverlight 8.1. If you want to support background audio playback, you can continue to use a Windows Phone 8 app or create a Windows Phone Store app, which supports new background audio APIs.
So in this case you will have to write app that target WP8.0 Silverlight or or WP8.1 Store app.
The similar question was here at MSDN forum.
You can achieve that by Creating a new Windows Runtime Component. This is where your entry point for the Audio task will be. The entry point is a class that implements IBackgroundTask. This gives you one method that will be invoked on startup of the Audio task named Run.
In order to keep the Task alive indefinitely you need to keep track of the deferral that exists on the IBackgroundTaskInstance. Placing the deferral in a field for safe keeping will be enough. When the operating system cancels your task you will need to call Complete on this said deferral.
An example of a bare bone implementation of your task should look something like the following
public sealed class AudioPlayer : IBackgroundTask
{
private BackgroundTaskDeferral _deferral;
public void Run(IBackgroundTaskInstance taskInstance)
{
_deferral = taskInstance.GetDeferral();
taskInstance.Canceled += TaskInstance_Canceled;
}
private void TaskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
{
_deferral.Complete();
}
}
for more Refrence you can go here

how to lock the screen programmatically in windows phone 8?

We can prevent the screen to lock using the below code
PhoneApplicationService.Current.ApplicationIdleMode = IdleDetectionMode.Disabled
and
PhoneApplicationService.Current.UserIdleDetectionMode= IdleDetectionMode.Disabled
but how to lock the screen from my app. Like the below app
http://www.windowsphone.com/en-us/store/app/one-touch-lockscreen/a3b1220b-1f9a-4bf0-93bc-21ed02792279
Thanks in advance
It's pretty hacky. It's not in the official API, so it could stop working at any time, just like the volume control API. Anyway, it you want to do it, you need to use this external method:
[System.Runtime.InteropServices.DllImport("ShellChromeAPI.dll")]
private extern static void Shell_TurnScreenOn(bool value);
For WP8.0 app this needs to be in a Windows Runtime Component (you should reference its output, as the project cannot be referenced).
From what I understand, though, this won't work on WP8.1 devices, so you'll need a separate WP8.1 app and I think it needs to be a XAML (Windows Store) app.
What #yasen wrote is correct.
[DllImport("ShellChromeAPI.dll")]
private extern static void Shell_TurnScreenOn(bool value);
I've tried the following cases:
Runtime 8.1 C# (Passed store certification)
Runtime 8.1 C++ with Runtime Component 8.1 C# (Haven't tried to publish this in store)
Silverlight/DirectX 8.0 C++ (Passed store certification)
Here's the link to my app that's using the last solution mentioned above.
http://www.windowsphone.com/s?appid=38bf5918-025e-4f23-b515-2cac451a84ab
And I've heard about cases in store using Silverlight that supports 8.0 and 8.1.
You can get Screen is locked or not by Windows.Phone.System.SystemProtection.ScreenLocked
but Unfortunately There is no way to lock the screen via code in Windows Phone 7.x or 8.

cocos2d-x c++ -> java for android

Currently I'am developing a game using cocos2d-x.
Of course, for multi-platform use.
basically I use a xcode for coding and development.
I want to attach IAP(In app purchases) separately to each coding for iPhone and Android
Problem to try to call a function of a certain class in Android that did not work.
Sources include the following:
cpp side
MyClass::invoke_init()
{
JavaVM* jvm = JniHelper::getJavaVM();
JNIEnv* env;
jvm->GetEnv((void **) &env, JNI_VERSION_1_2);
jclass cls;
jmethodID method;
cls = env->FindClass("com/joycestudios/game/SampleActivity");
method = env->GetMethodID(cls, "initFunc", "()V");
env->CallVoidMethod(cls, method);
}
java side
public class SampleActivity extends Cocos2dxActivity
{
public void initFunc()
{
Log.v("LOG_INFO", "initFunc()");
}
}
The first test as follows: I'm in progress.
build from xcode and build from build_natvie.sh and last build from eclipse.
But after run on eclipse, Just black screen and shuts down.
How to call a function of a java class?
What I looked at several samples, including also analyze the problem, I do not see any problems?
Can you tell if you find any error log?
First check if your game is working fine on android..
Den we can have a look how to call the function.
Generally for calling native method I use MessageJni class available in Cocos2d-x library.
I create my methods in MessageJni class which calls for native methods.
Its easy and convenient way of calling native methods.
Just google using MessageJni class. It will ease your work.
:)