This is similar to how MvvmCross allows users to make phone calls.
When using this template:
ViewModel code uses a platform-independent service through an interface - for example:
public interface IMvxPhoneCallTask { void MakePhoneCall(string name, string number); }
consumed
protected void MakePhoneCall(string name, string number) { var task = this.GetService<IMvxPhoneCallTask>(); task.MakePhoneCall(name, number); }
at https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20CirriousConference/Cirrious.Conference.Core/ViewModels/BaseViewModel.cs
The application configuration code implements a platform-specific implementation for the interface - for example:
RegisterServiceType<IMvxPhoneCallTask, MvxPhoneCallTask>();
In WP7 - uses PhoneCallTask - https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross/WindowsPhone/Platform/Tasks/MvxPhoneCallTask.cs
public class MvxPhoneCallTask : MvxWindowsPhoneTask, IMvxPhoneCallTask { #region IMvxPhoneCallTask Members public void MakePhoneCall(string name, string number) { var pct = new PhoneCallTask {DisplayName = name, PhoneNumber = number}; DoWithInvalidOperationProtection(pct.Show); } #endregion }
In Droid - it uses ActionDial Intent - https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross/Android/Platform/Tasks/MvxPhoneCallTask.cs
public class MvxPhoneCallTask : MvxAndroidTask, IMvxPhoneCallTask { #region IMvxPhoneCallTask Members public void MakePhoneCall(string name, string number) { var phoneNumber = PhoneNumberUtils.FormatNumber(number); var newIntent = new Intent(Intent.ActionDial, Uri.Parse("tel:" + phoneNumber)); StartActivity(newIntent); } #endregion }
In Touch - it just uses Urls - https://github.com/slodge/MvvmCross/blob/master/Cirrious/Cirrious.MvvmCross/Touch/Platform/Tasks/MvxPhoneCallTask.cs
public class MvxPhoneCallTask : MvxTouchTask, IMvxPhoneCallTask { #region IMvxPhoneCallTask Members public void MakePhoneCall(string name, string number) { var url = new NSUrl("tel:" + number); DoUrlOpen(url); } #endregion }
In the vnext version of mvvmcross, this approach is further formalized using plugins - see a brief introduction to them in the 'going portable' presentation at http://slodge.blogspot.co.uk/2012/06/mvvm-mvvmcross-monodroid-monotouch- wp7.html
For example, in vNext, the above phone call code is contained in the PhoneCall plugin - https://github.com/slodge/MvvmCross/tree/vnext/Cirrious/Plugins/PhoneCall
One of the problems of your task may be the word "any" - differences in platform implementation can make it difficult to define a cross-platform interface that works on all platforms for any of NFC, Bluetooth, etc., let one of them.