How to create Dart package to use in Android and Swift Projects? - android

I have an application that use Flutter. In application, i am using flutter_blue_plus package to communicate ble devices. I wrote also a bluetooth service to handle packaging, encoding (AES for example) sending data. i want to make that bluetooth service(dart code) like package to use in other application like native android or iOS applications. Is there a way to make it?
Appreciated any documention, video or example code.

Check the officials docs Developing packages & plugins
Else check for some tutorials.

Related

Adding native Android code to a Flutter app

I'm trying to add native android code to an already existing Flutter app, that does something quite different.
So I'd just like to have all of that functionality on top of my current app.
The native android app is using Bluetooth to connect to an external device and is collecting data periodically.
I know, that there is the possibility to call native code via platform channels, but it seemed to me, that you'd have to call that code every time you want to use it? Is this a reasonable way to implement the app or should it be rewritten in Dart? What's the best practice here?
Hope you can help me, thanks a lot!
The purpose of platform channels is to call platform-specific APIs.
...you'd have to call that code every time you want to use it...
Correct.
...Is this a reasonable way to implement the app or should it be rewritten in dart? What's the best practice here...
Check the source code of any package that relies on platform channels (for example camera, file picker, etc.) and read the official documentation. As a short summary, platform-specific code is written in Kotlin/Java (Android), Swift/Objective-C (iOS) or C/C++. Dart is used for building the UI and communicating with said code via platform channels and messages.

NFC read/write with flutter

I'd like to give a try with flutter, but so far I have found only NFC reader plugin. I will need two other things.
react on NFC tag present intent and then maybe use NFC plugin to read it
write to NFC tag, probably using Platform channels
I just need to confirm it is feasible at all with flutter and will need the kick in the right direction, before I will leave plain android.
perhaps I am a little late to the party, however as I just tackled a very similar problem, I want to weigh in on this topic:
So reading/writing NFC with Flutter is possible. As mentioned before you need a platform channel in order hand the command to the native system, AND an event channel, if you want to read data to your flutter app, to accomplish this task.
The best way would be, if a plugin was available to handle this, however I could not get the one which you mentioned too to work with my flutter app (specifically, because I tried with IOS and swift).
However here are some ressources, from which I puzzled together my system:
Communication from flutter to native system via platform channels: This link is the offical flutter page which interestingly only described the communication from flutter to native system, but not the other way around. For the other way you need:
Communication from native system to flutter app via event channels: (yes you need a different channel for the communication back to the flutter app). This example is only for android. For swift, all I could find was this ressource, which however seems to be a bit old.
NFC Tutorial for IOS: This is actually pretty simple as long as you have a developper account. A good minimalistic tutorial can be found here
NFC Tutorial for Android: This is actually even simpler, as nfc is longer established on android. I like this one
I think what you're looking to do is definitely possible, but as you mentioned in your question you will have to use Platform Channels.
The platform channels can go both ways; you should be able to set it up so that your main activity receives the NFC tag present intent, and then you send a method call from android to dart. Or you could start listening from dart and then have the method return when the intent is received.
Writing to NFC is about the same, you use method channels to call across.
Depending on what you're doing, you may want to consider splitting the NFC functionality into a plugin, even if you don't end up publishing the plugin.
With this fork from flutter-nfc-reader you can now read and write nfc tags from android and read them from ios https://github.com/semakers/flutter-nfc-reader
to install add the following dependency your pubspec.yaml
dependencies:
flutter_nfc_reader:
git:
url: git: //github.com/semakers/flutter-nfc-reader.git
ref: master
In the Readme.md of the repo are the installation and use instructions.
Happy NFC Tag writing!!

Is Xamarin the right choice for Android and IOS long running service

My specific task requires that I write a long running service for Android. The service should be running all the time unless the user specifically shuts it down. This I can do. However, one of my managers suggested I look into using Xamarin so we could also run this on Windows 10 and iOS. I have no experience with Xamarin or iOS so I am struggling to find any advantage to using Xamarin for this specific task, other than perhaps the code base is all in C#.
1) Does anyone have any experience with writing this type of service in Xamarin for multiple OS and if so can you offer any insight?
2) Will I have to write separate c# code for the Android, iOS and Windows implementations of the service?
3) If anyone has any compelling reasons to champion Xamarin for this task please let me know your thoughts.
Thanks
Xamarin has ported all the Android / iOS libraries to C#. Hence you can write the code in C# language but the Android Service still works in the same way.
What you will essentially do is create a PCL code (shared library) which can be used across the platforms like iOS / Android. All you business logic goes here in this library. Make sure any platform specific code is not here.
Now you will create separate projects for Android and iOS which will use the above mentioned PCL library. This is platform specific non PCL code.
For example : In Android Project, you will still use
StartService(intent) to start the service but say onHandleIntent(), you will call the PCL(shared library) code.
I would recommend to inject the dependency on PCL code as and when required.
Please Note : If the lines of code in the shared library is considerably very less as compared to platform specific code then it makes no sense to choose Xamarin over native.

Is it possible to use the Android NDK for Android Wear apps?

I look forward to create an android wear application with some 3d content. That for I like to reuse libraries written in C/C++. Is it generally possible to create an Wear APP with the NDK? Do you know about any primer or example code which does so?
I just tried it, and can confirm that is possible to call native code through JNI on Android Wear. It works exactly the same as it does on regular Android.

Sharing code between GAEJ and Android projects

In Eclipse:
Is it possible to Sharing code between GAEJ and Android projects? And or GAEJ and another GAEJ?
Thanks
there was a nice talk about GAE & Android integration on the last GoogleIO 2012:
Google I_O 2012 - Building Mobile App Engine Backends for Android, iOS and the Web
they show how to use same data structures for data exchange between Android and GAE.
If you asking about how to set it up in Eclipse, I use the 'linked source' option in the source tab of Java Build Path. Here's a blog post with details:
http://blog.christoffer.me/2011/01/sharing-code-between-multiple-java.html
If you are asking about whether it is practical - from the code perspective - that is trickier.
When trying to share Android code with GAE/J I discovered that I had dependencies on android packages, e.g. android.util.Base64. Sharing code means dropping stuff like this and using 3rd party libraries instead. For example, the Guava library works on GAE/J and Android:
http://code.google.com/p/guava-libraries/
Logging is another problem. My GAE/J code was writing to java.util.logging.Logger, whereas my Android code ultimately logs to 'android.util.Log.println. If you use a common library framework like log4j or just writing to System.Out I think you will lose functionality in the log viewer - ideally you would have a logging library or shim that mapped to java.util.logging.Logger or android.util.Log.println depending on the platform.

Categories

Resources