API is pretty scarce right now, don’t know if it’s because that’s all there is to it right now, or it’s imcomplete…
Hi! For what platform ?
There is no abstraction API but you can use the Android and iOS APIs directly.
I was hoping both, I guess Android first
How do I use native API on the fuse platform? This could be very well a good solution, since I’m pretty proficient with Java
Add a package reference to the Android
package. Then just write
var recorder = new Android.android.media.MediaRecorder()
See http://developer.android.com/reference/android/media/MediaRecorder.html
Thanks, but I don’t see android.media in the edit reference… or is Android enough?
You just need the Android
package, it contains all the android.*
namespaces.
Thanks, I created a new project, and added one simple class called Helper (I added the Android reference):
using Uno;
using Uno.Collections;
using Fuse;
namespace Recorder
{
public class Helper
{
Android.android.media.MediaRecorder recorder;
public Helper() {
recorder = new Android.android.media.MediaRecorder();
}
}
}
when compiling, I got an error:
EUNKNOWN: Android.android.media.MediaRecorder.ctor() cannot be used in this context because it is marked with Uno.Compiler.ExportTargetInterop.ExportConditionAttribute
Any idea what I’m doing wrong? I haven’t even began to use this class…
I think the problem here is that Android bindings can only be used on an Android build. You might be building for Fuse’s simulator where they aren’t available.
When using platform-specific code, such us when you use bindings to native APIs, you’ll need to attribute some classes or functions with [ExportCondition("Android")]
or inside if (defined(Android)) { ... }
blocks.
Typically, if you’re targetting multiple platforms, as we expect you will, you’ll define a common interface that is implemented specifically for each platform, the implementations of which would be tagged with the ExportCondition
attribute. You’d also have a factory method for the interface that specifically instantiates the appropriate class inside a platform-specific if (defined(Android)) { ... }
block.
I have an example building up to this, but with only an iOS implementation, you can look at here: https://gist.github.com/biochimia/74e16bdf8f57cf5ba3de
Added a fix to make the error message more easy to understand. In the next version, it will say:
'Android.android.media.MediaRecorder' can only be used in 'Android' export. Consider adding [ExportCondition("Android")] to your class, or put the code inside 'if (defined(Android)) { ... }'