I learnt that Xamarin.mobile provides single set of APIs across platforms. But implementing in a cross platform app, how does it look like?
A cross platform architecture consists one project containing shared codes (core project) and other project consisting the UI codes per platform. So, as Xamarin.mobile provides a single set of API, how can we utilise it to write once and use everywhere? Eg: implement mediapicker.TakePhotoAsync in one class and use it in multiple platforms without writing the same code in other platform. Because, the sample app i downloaded from Xamarin.mobile consists of apps developed for different target individually (not cross), though i see they use the same media picker, geolocation and contacts namespace across different platforms.
Thank You!
Xamarin's 'traditional' approach to cross-platform apps has been to use file-linking.
I believe this is currently changing to a dual approach of recommending either:
file-linking
or
Portable Class Libraries (PCL)
The first version of Xamarin PCL support is due very soon (any day now).
When that becomes available and stable, then I expect you may see new versions of xamarin.mobile which are available for PCL. Also, they have indicated that they may open source xamarin.mobile. As it stands today, I don't think xamarin.mobile is a very active development - I don't believe it's changed/grown much in the last year.
Until these changes happen, then if you want to use xamarin.mobile from portable code, then your best bet may be to either follow the file-linking route, or to use PCL libraries but use some form of facade to wrap the native xamarin.mobile libraries inside an injectable interface
Related
We are developing a cross platform mobile application using Xamarin. I have noticed there are different ways of structuring your code using Shared code or PCL/.net standard.
I attempted to use .net standard and what i have found is that it doesn't include all the libraries such as using ado stuff , datatable/datasets using system.data. Or using system.net for example. Other functions have less overloads and seems that its a stripped version of .net to work across platforms. Is there any way to add this functionality or use a broader range of .net?
You are correct - .Net Standard and .Net Core are stripped down versions of the full .Net framework. They contain only features that can be used on all platforms (Mac, Android, iOS, Linux, Windows, etc.)
The full .Net framework only needs to work on Windows, so there are additional things that you can do based on the fact that there is less complexity in implementing and that the code base is more mature (cross platform is still pretty new by C# standards). To the best of my memory, System.Net should work if you have your references correct, but System.Data will not (or at least direct database access is not possible)
You can regain some functionality through NuGet packages, but it won't be the same as using WinForms or something like that...
My best advice would be to program against an API. You can use a web server that runs on the normal (full) .Net framework, and does all the heavy lifting using all the .Net features that you are accustomed to. Your Xamarin app would send and receive data from the API and basically provide a mobile front end for whatever you are doing. This approach makes sense for most apps anyway, and is generally what you would be doing anyway if you used Swift and Java to create separate iOS and Android apps.
I am new to Xamarin. Can someone point me to a way to read existing SMSs using Xamarin Forms.
I know we can do it using Android specific libraries (and probably with iOS specific libraries as well). But, I want to use a library that will help me avoid using platform specific library.
You will have to use platform specific code for this. Remember; all libraries out there actually are platform specific code but just offer you an abstraction. This includes Xamarin.Forms itself.
As mentioned by Jason in the comments, you aren't going to be able to do this on iOS altogether, they do not allow to read or sends texts directly. So you should probably rethink what you are trying to do.
i was just wondering what the benefits are in using PCL with Xamarin.Forms.
I mean you share the Code between each Platform anyway.
In Xamarins native approach it is quite clear.
So maybe anybody can tell me why to use PCL in Xamarin.Forms?
PCL allows the maximum in code sharing across platforms. PCL will by it's very nature limit you to using only those API's that can be shared from platform to platform.
While you can use Shared Projects, you will find yourself using compiler directives and making coding sacrifices that can lead to bad coding practices across anything but the smallest of projects.
Using the Xamarin Forms 2.3.3 or later you can of course embed Platform Specific Controls in your Xamarin Forms pages in your PCL and they will only render when run on the platform.
In addition of maximum code sharing, it allows you to follow best practices like SOLID.
Also, please remember that there are 3 choices (not only 2):
Portable Class Library
Shared Library
.NET Standard Library
.NET Standard Library is still an ongoing work in process, so it's not there yet. But, it will be the way to go!. So, PCLs today can give you an excelent migration path to the .NET Standard Library way tomorrow.
Hope this helps.
To my knowledge, Xamarin is cross platform framework, so I can build one app and share it to any platform (Android, iOS, and Windows phone). I can't find any documentation that demonstrate how to port an existing Android project (completed project) to other platform, What are portable parts in the project, and what parts that can't be ported? Could you please explain these points in simple words. Thanks in advance.
When using Xamarin.Forms, projects are constructed in two parts:
A PCL project which contains the shared code; this includes business logic and classes which define user interfaces for the application (these can be written using C# or XAML with a C# code-behind). These user interfaces are platform-agnostic as Forms defines elements which are common to all platforms (buttons, labels, entries, etc.), and those translate into the native controls on each respective platform.
One or more platform-specific projects which contain boilerplate code to get the application up and running (such as the AppDelegate on iOS or MainActivity on Android), as well as any platform-specific behavior via the DependencyService, custom renderers, or the recently added effects. These three aforementioned features are not necessarily mandatory, but for times when you need to access platform-specific features, you may need to use one depending on your requirements.
See here for a quickstart guide on how to get a Forms-based application up and running.
I don't see how Qt does the low level graphics work, in order to create its own custom GUI look/feel for each platform. Does it utilize each of the platforms APIs or something? I ask because I am really wondering how I could go about creating my own framework in order to make a custom GUI application with a unique graphical look.
"How does QT only use C++ to make custom GUIs for some many platforms?"
"Does it utilize each of the platforms APIs ... ?"
You answered your own question. It makes a common library for developers to write their applications with. The application developers write their application only once, not caring about platform specifics. Then, the library author puts out different versions of the library for each platform, which handles all the specific UI calls. This is called encapsulation:
http://en.wikipedia.org/wiki/Information_hiding#Encapsulation
If you were to write your own such library, you would need to figure out what is common between all of the platforms you target, or figure out what high-level concepts your application would need, and create that abstraction. Then, implement that abstraction for each of the platforms you wanted to support.
Edit:
Also see Juliano's comment. This seems like it might be closer to what you want to do, rather than the question you asked. I'd not re-do the work that Trolltech or the WxWidgets team or the Gtk guys or the Mono people did, if I could possibly avoid it.
The good people at Trolltech (now Nokia) write all the platform specific code for you. Only the interfaces to their library remains the same across platforms. You do have to make sure that you only use their classes and don't make any OS-specific calls.
If you want, you can modify the graphics and the handlers to extend the Qt library and create your own look and feel.
Your Qt application doesn't have to have the plain standard platform graphical look, but there are ways to design unique apps with Qt.
For instance, you can style your application with style sheets: http://doc.qt.io/qt-5/stylesheet.html, or even with a custom QStyle (which is not very easy): http://doc.qt.io/qt-5/qstyle.html
Qt Quick is a new technology we're introducing in the upcoming Qt 4.7 (check out the beta if you're interested). It allows you to easily define custom UI components from simple primitives, with custom animations, state transitions and other effects. See for example http://www.youtube.com/watch?v=8G4U7QWRajg.