Insert unity as in a subview in android and plug in - android

I have to build an android app in which I have to integrate unity player with an existing android application. I need to get values from a sensor and animate the gameObject in unity. Should I make a plugin using ndk or jni? Please help. I'm new to this. I have read the docs but I am confused.

You can choose to build an Android Studio project instead of an APK. To do this, select the "Google Android Project" checkbox from the android build settings.
This will give you a project with a main activity which is a UnityPlayerActivity. You can add/remove activities, views and do anything you want with the project. You should also be able to move the contents to another project and merge them. The important thing here is to keep all the libraries and resources Unity builds intact. This should all feel natural if you're familiar with Android Studio.
To pass data to/from Unity, you can use the AndroidJava* classes, which essentially allow you to call any Java code (from the OS libraries or your app package) as if you were using reflection API.

Related

Use both JavaFx + Acitivity on Android

So, in my project, I'm merging a few pieces of code, written earlier, into one application. I have :
some Android activities (i.e. Maps activity, login activity)
some JavaFX controls / forms (used before on Windows client).
Now, I would like to reuse those JavaFX forms on my Android application, but still be able to load my previous Android activities on some button click or sth.
Is there any way, this could be achieved ? Greetings
If you want to merge JavaFX and Android projects, you should have a look at the JavaFXPorts project.
You will be developing a JavaFX project that could be deployed both in desktop and on mobile platforms.
For that, you just need to include one single plugin on your build.gradle:
apply plugin: 'org.javafxports.jfxmobile'
For starters, you may consider using Gluon's plugin for NetBeans, that will create for you a JavaFX project where you can add your sources: you could add your existing JavaFX sources to the Main folder, and you could add also your Android activities to the Android folder.
You will have to adapt the Android activities so they run on the JavaFX thread with FXActivity.getInstance().
Have a look at this post with a sample of that.
You may also have a look at Gluon Charm Down library, that can be added to your project, to interact with native services, like GPS.
Keep in mind Android runs Dalvik VM, so you won't be able to use Java 8 new features (streams).
Android SDK doesn't come with any Java gui library. If it is mandatory for you to reuse the same form (i.e. refactoring will take weeks), Jose answer is probably what you need.
But if it's not mandatory (i.e. you just want to avoid 1 or 2 hours of writing code), I'd suggest you just re-code it using Android UI classes, as it will make it easier to maintain and scale in the future.

How is Basic4Android IDE to create complex application

I am planning to create a complex application which has lots of Database requests and Network data sending back and forth. Is it advisable to use Basic4Android(B4A). I am confused ? I downloaded the trail version and liked it because its easy atleast at the beginning, don't know about later examples. The points am concerned about is
1> Is it possible to Customize Controls Easily using Basic4Android.
2> Is it fast as compared to Eclipse in terms of understanding and coding time.
3> Updating Application later when want to add new features.
4> Can the API available for android can be used in Basic4Android, Like the jar files which we add as external jars to the classpath can that be done in B4A?
5> Also can a plugin kind of application be made in Android , if yes then is it possible using B4A?
If someone has made application using B4A please Guide me.
Currently am trying the examples from the guide the B4A guys have on the web and am finding it amazing. But I need an expert "REVIEW" who has previously worked on B4A.
I need to work on application ASAP.
Thanks in advance.
1> Is it possible to Customize Controls Easily using Basic4Android.
Yes, you can use images,panel and reflection lib to customize
2> Is it fast as compared to Eclipse in terms of understanding and coding time.
Yes learning curve is very short
3> Updating Application later when want to add new features.
You can save the b4a project and change when ever you need to update.
4> Can the API available for android can be used in Basic4Android, Like the jar files which we add as external jars to the classpath can that be done in B4A?
You can add (wrap) external jar files in Eclipse or use B4A Simple Library Compiler. Check out tutorials. You can also make your own libraries
5> Also can a plugin kind of application be made in Android , if yes then is it possible using B4A?
Depends on what plugin you want to make. The source code of apk created by B4A app is stored in src folder. You need to check out whether it can be incorporated in your android IDE.

How to pass data from Unity scene to Android Activity

Hello I am currently writing an Android app that uses Unity to display a 3D model. The user is capable of interacting with the model as selecting objects in the scene. What I am having trouble is passing data back to the Android activity.
I currently have the Unity scene executing as a subview, can anyone point me in the direction on how to pass data from the scene to Android?
Do I have to create a Java plugin, explained here?
link text
If this is the case, does anyone have any tutorials on this? The original material is kind of lacking. Thanks in advance.
If you want to communicate from Unity to an Activity (Java code) you need to create a native plugin. Then in C# from Unity you can find the activity or the JavaObject and pass it parameters.
Check this out.
https://www.thepolyglotdeveloper.com/2014/06/creating-an-android-java-plugin-for-unity3d/
After you watch this page the summary would be:
Create a simple Unity Project.
Create an Android native plugin. Can be an activity or a simple class.
Export the .jar or .aar from Android Studio (i recommend the .aar since it's the android studio library. There you can manage the AndroidManifest.xml and then Unity will merge it with the final one)
Put the .aar into Unity project under Assets/Plugins/Android folder.
Create a c# script calling for your class method.
Build the .apk from Unity (Remember adding the company, product name and bundle id)
Run the apk in a device.
Test
I'm not sure since I haven't worked with Unity before. But there are some ways to transfer data between activities, I hope it'll help you.
Intent
Parcelable

How to keep two versions of the same android app?

It's quite often that we see two versions of an android app: a paid version and a free version. I'm also developing an app that would like to release two versions. What is the best way to do this? Creating two projects and copying files in between does not seem to be the best way in my mind.
Use Library Project, as the official dev guide suggested:
If you have source code and resources that are common to multiple Android projects, you can move them to a library project so that it is easier to maintain across applications and versions. Here are some common scenarios in which you could make use of library projects:
If you are developing multiple related applications that use some of the same components, you move the redundant components out of their respective application projects and create a single, reuseable set of the same components in a library project.
If you are creating an application that exists in both free and paid versions. You move the part of the application that is common to both versions into a library project. The two dependent projects, with their different package names, will reference the library project and provide only the difference between the two application versions.
Update: This method is really only good for compiling with Eclipse, since Android Studio supports build flavors which can achieve exactly this.
While #yorkw's and #Nate's answers are both good, this is the method I use due to its simplicity. From the article:
com.example.myapp – Android Project Library - This is where my ENTIRE app lives. All the functionality for the FULL and LITE versions.
com.example.myapp.full - Android Application Project - This is a shell that contains graphics and resources needed for the full version only. Basically it’s a super lightweight shell.
com.example.myapp.lite - Android Application Project – This is another shell that contains nothing but graphics and resources needed for the lite version. Again, its a super lightweight shell.
I also keep a static variable IS_PRO in a library class which is set when the app launches. This should be used only for notifications, alerts, and so on (such as asking the user to upgrade to pro).
However, this method has one drawback: you must clean and rebuild any time the library or its resources are modified. Also be sure to read this post on sharing resources between a project and a library.
I would call this a FORK in development. Start a new App development, but have your common code coming from a common file location. Make your free based edits to the forked code, and try your best to keep that code completely separate.
I actually did this on an iPhone based app, I have a free version and 2 different payed versions (a single player only and a multi-player). I would do it the same way on Android.
U can use git for example.
Create branch "app_with_ads", and master will be your "paid" version.
Develop in master and merge periodically to another.
before publish u probably will have to change app package, or something else in Android\ Manifest.xml
Here's a little blog tutorial about doing this.
Basically a howto for building a Full and Lite version of the same app, using a library project to accomplish code reuse between the two versions.

Release several android applications with same code base

Hi: I want to release multiple applications to android marketplace which are all very slightly customized based on a code base. I can't just change the package indentifier in the AndroidManifest.xml file because several other things dependet on this like action identifiers and so on.
What is the best approach to release several apps based on one eclipse project with the same code base?
You need to create a library project and reference it from every of your apps. Latest versions of ADT plugin allow this. Go to the project properties, android page, you'll see a 'library' checkmark there. Reference to the library is also setup on the page.

Categories

Resources