Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Android System for Unity

Discussion in 'Assets and Asset Store' started by evandropaulino, Jun 20, 2013.

  1. evandropaulino

    evandropaulino

    Joined:
    Aug 7, 2012
    Posts:
    21
    Android System for Unity

    Extend you Android app simply!!! Android System allows developers to interact with Android core funcionality entirely in C# world:

    • Share data with Android Beam (NEW!!!)
    • Pick images from gallery with Picker (NEW!!!)
    • Make phone calls and send SMS (NEW!!!)
    • Listen system events with Broadcast Receivers
    • Call other apps with StartActivityForResult and receive results on OnActivityResult delegates
    • Interact with system services through ServiceConnection and Binders

    Following is an example of sharing data with Android Beam:

    Code (csharp):
    1.  
    2. GUIText txt;
    3.  
    4. NFC.Subscribe( ( string msg ) => { txt.text = "Received NFC message " + msg; } );
    5. NFC.Publish( "Android Beam test message" );
    6.  
    7.  
    No additional Java libraries, no need to mantain and debug a separated project in Java side.

    Other updates:
    • No more IntPtr, all low-level callbacks uses AndroidJavaObject instances as arguments
    • Callbacks can be instance methods, lambdas or delegate methods

    Other funcionalities are in the roadmap:
    • Receive broadcasts while application is not active
    • Pick contacts and other media types
    • Receive SMS messages
    • Editor tool to configure Android Manifest, adding permissions, features and other configurations

    Visit the project page here
    Asset Store link: https://www.assetstore.unity3d.com/#/content/9807
    If you have any suggestions, send an e-mail to fourthskyinteractive@gmail.com.
     
    Last edited: May 13, 2014
  2. evandropaulino

    evandropaulino

    Joined:
    Aug 7, 2012
    Posts:
    21
    Hello people.

    If you want to preview all the new functionalities available for the library, you can try the demo in Google Play: https://play.google.com/store/apps/details?id=com.fourthsky.androidsystem

    I need to show one more example, the new Picker class. It opens the gallery, allowing you to choose and image, and returns the image as a texture in the callback:

    Code (csharp):
    1.  
    2.  
    3. GUITexture guiTex;
    4.  
    5. Picker.PickImageFromGallery( (Texture2D tex) => { guiTex.texture = tex; } );
    6.  
    7.  
    Keep in touch for the news!!!
     
    Last edited: May 13, 2014
  3. the1plummie

    the1plummie

    Joined:
    May 3, 2013
    Posts:
    2
  4. evandropaulino

    evandropaulino

    Joined:
    Aug 7, 2012
    Posts:
    21
    Hi plummie

    The problem is that there's no support to implement interfaces in C# yet. This feature will be available in the next version.
     
  5. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    Hi,

    I'm looking for a way to create an email from within my app with a HTML body. Is this possible with your plugin?
     
  6. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    500
    I really like your idea. I was trying to share an image (via Intents) by just using C#. I managed to share text, but couldn't figure out how to share an image.
    It would be great if all the Android native functions could be accessed with just C#.
     
  7. Breakmachine

    Breakmachine

    Joined:
    Sep 19, 2009
    Posts:
    39
    Hi. Does your plugin work well with other plugins? We're using quite a few plugins and SDK and have had some issues, especially regard the AndroidManifest XML.
     
  8. evandropaulino

    evandropaulino

    Joined:
    Aug 7, 2012
    Posts:
    21
    Breakmachine, the plugin has only one limitation, and it's very specific: you need to use AndroidSystem.StartActivityForResult (to call another and get results from it, like and image from gallery or a contact from phone book), you need to use the activity from plugin and the manifest from it. Otherwise, there's no need to use it.

    Meanwhile, I'm preparing a full source version of the plugin, so you can use your activity and merge with the funcionality of Android System. I'm expecting to release this new version in about three weeks. And I'll add more sample codes with some funcionalities, like the requests from the users of this forum and others that bought the plugin.
     
  9. Melphis

    Melphis

    Joined:
    Jul 9, 2013
    Posts:
    3
    I'm trying to use android.nfc.action.TAG_DISCOVERED. I added to manifest:
    Code (csharp):
    1. <uses-feature android:name="android.hardware.nfc" />
    2. <uses-permission android:name="android.permission.NFC" />
    3.  
    4. <activity android:name="com.fourthsky.unity.androidtools.UnityPlayerProxyActivityEx" ...
    5. ...
    6.   <intent-filter>
    7.     <action android:name="android.nfc.action.TAG_DISCOVERED" />
    8.     <category android:name="android.intent.category.DEFAULT" />
    9.   </intent-filter>
    10. ...
    11. </activity>
    12.  
    main code:
    Code (csharp):
    1.  
    2.  
    3. public class AndroidEvents : MonoBehaviour {
    4.  
    5. private const string NdefDiscovered = "android.nfc.action.NDEF_DISCOVERED";
    6. private const string TagDiscovered = "android.nfc.action.TAG_DISCOVERED";
    7.  
    8. void Start() {
    9.             var receiver = new BroadcastReceiver();
    10.             receiver.OnReceive += Receive;
    11.             receiver.Register(NdefDiscovered, TagDiscovered, "android.intent.action.BATTERY_CHANGED");
    12.         }
    13.  
    14. void Receive(IntPtr ptr, IntPtr intentPtr) {
    15.             var intent = AndroidSystem.ConstructJavaObjectFromPtr(intentPtr);
    16.             var action = intent.Call<string>("getAction");
    17.             Debug.Log(action);
    18.         }
    19.  
    But no one event on read card.

    If to replace:
    receiver.Register(NdefDiscovered, TagDiscovered, "android.intent.action.BATTERY_CHANGED");
    to singe param method:
    receiver.Register(NdefDiscovered);

    I have exception:
    Exception at class FourthSky.Android.BroadcastReceiver: line 52

    With BATTERY_CHANGED all fine, it's work;

    Is that my fault? Maybe i can't use with this plugin android.nfc.action?
     
  10. evandropaulino

    evandropaulino

    Joined:
    Aug 7, 2012
    Posts:
    21
    You can use the plugin to access NFC, not using BroadcastReceiver, but with OnNewIntent callback. If you can wait some more days, I'm finishing a version of Android System with a simples API to access NFC, SMS, contact and media pickers and more. Will be easy like this:

    Code (csharp):
    1.  
    2. NFC.Subscribe( ( string msg ) => { Debug.Log("Received NFC message: " + msg); } );
    3.  
    And the other device will do:

    Code (csharp):
    1.  
    2. NFC.Publish("Testing NFC");
    3.  
    I'm just to the final tests to submit to asset store. I only ask a little more patience, the result will be great.

    Thanks.
     
  11. evandropaulino

    evandropaulino

    Joined:
    Aug 7, 2012
    Posts:
    21
    Hi people,

    Just to alert, the new version of Android System for Unity is available on Asset Store.

    See the first post with the update information.

    If you have any doubt, please sent an e-mail to us!!!!
     
  12. Cheshire Cat

    Cheshire Cat

    Joined:
    Sep 18, 2012
    Posts:
    39
    Hi,
    I'm looking for a functionality which allows to register intents with AlarmManager and being able to get it back on time, even if the application is not running. You mentioned you were planning to do that, is it implemented now?

    10x
     
  13. evandropaulino

    evandropaulino

    Joined:
    Aug 7, 2012
    Posts:
    21
    Well, what is in development is a feature to allow Broadcast Receivers to be registered to receive broadcasts while application is not running. But we have some problems here.

    First, there's no easy way to running C# code (and even Unity APIs) with background BroadcastReceivers. Is this problem that will be addressed by this new feature. Second, the AlarmManager will just enable the broadcast to be issued, but I'm still thinking how to HANDLE the action.

    I'll have more details in the next days. You can follow my Twiiter @FourthSky to have more details soon.

    Thanks.
     
  14. Cheshire Cat

    Cheshire Cat

    Joined:
    Sep 18, 2012
    Posts:
    39
    Thanks for the answer. But if an application is running, is it possible to register and receive intents from the AlarmManager?
     
  15. evandropaulino

    evandropaulino

    Joined:
    Aug 7, 2012
    Posts:
    21
    Yes, it is possible. But the alarm intent must be handled by an Broadcast Receiver, OK?
     
  16. Quiet-Pixel

    Quiet-Pixel

    Joined:
    Aug 23, 2013
    Posts:
    48
    Can you give some quick instructions on how to integrate your plugin into an Android project. I am having trouble getting even the test scene to work correctly. Does Unity automatically package the JAR file into the project, or do I need to export to an Android project and add that JAR manually? What about the libunityandroidsystem.so file, does it have to be added somehow, if so how? Finally, are the additional activities in your sample AndroidManifest.xml necessary for the project to work?
     
  17. Quiet-Pixel

    Quiet-Pixel

    Joined:
    Aug 23, 2013
    Posts:
    48
    Ok, I got the test scene to work. I had to move your Plugins folder in Unity from /Assets/AndroidSystem up to /Assets. It seems that Unity (4.5.3) does not include a Plugins folder into the Android project unless it is at the root level of the /Assets folder.
     
  18. Quiet-Pixel

    Quiet-Pixel

    Joined:
    Aug 23, 2013
    Posts:
    48
    The AndroidSystemTools window is not working in Unity 4.5.3. Unity issues the following warning in the AndroidSystemToolsWindow.OnGUI () event inside the DLL:

    MissingMethodException: Method not found: 'UnityEditor.EditorGUILayout.BeginScrollView'

    I am guessing they changed the function signature since you last published an update.
     
  19. evandropaulino

    evandropaulino

    Joined:
    Aug 7, 2012
    Posts:
    21
    Well, this is unexpected, because this method exists (at least, in the documentation). I'll check it out.
     
  20. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,353
    Hi,

    I have few questions:

    1) Does it work with latest Unity build?
    2) Do you have API which checks if device supports Android Beam?

    Thanks!
     
  21. Darkling420

    Darkling420

    Joined:
    Apr 20, 2013
    Posts:
    27
    Compiled dll means eventually this may be useless, maybe even now if it's not support Unity 5 since no update in nearly a year. Is the source included?
     
  22. evandropaulino

    evandropaulino

    Joined:
    Aug 7, 2012
    Posts:
    21
    Hi.

    I'm adapting the plugin for Unity 5, and also including new features. I will upload the update to Asset Store next week.

    About the Android Beam, yes, there are methods to check availability of NFC and other features.
     
  23. Skatola

    Skatola

    Joined:
    Jan 17, 2013
    Posts:
    45
    Hi!
    i'm really intersted in your plug-in, i was looking for a way for make a phonecall in my app with a callback for come back to the app after the call end.
    It is possible with your plug-in? without any user interaction?
    thank you : )
     
  24. sb2

    sb2

    Joined:
    Feb 13, 2015
    Posts:
    3
    Hi,
    I just bought your "unityandroidsystem" package on the Unity3d asset store.

    Is it possible to read NFC tags with your package or only phon-to-phone comunication?
    Thanks in advance
    Giovanni Civati
     
  25. bakno

    bakno

    Joined:
    Mar 18, 2007
    Posts:
    595
    Hi

    I purchased the plugin. It seems this is a way to avoid writing Android plugins, correct?

    When do you plan to add a capability to receive SMS?
     
  26. brtbrg

    brtbrg

    Joined:
    Feb 17, 2015
    Posts:
    1
    Hi,
    Any news on Unity5 compatibility?
     
  27. Pixel-Wrangler

    Pixel-Wrangler

    Joined:
    Dec 16, 2014
    Posts:
    2
    I'm also wondering about Unity 5 compatibility. I bought the plugin in an attempt to load images from your Android photo gallery. I made a few minor changes to get it to build (e.g. .renderer -> .GetComponent<Renderer>()) and everything seemed ok at first. It opens the gallery but the callback that's supposed to retrieve the image data never gets called.
     
  28. Malik-Basit

    Malik-Basit

    Joined:
    Dec 5, 2012
    Posts:
    5
    I have bought the plugin for sending an sms message without opening sms composer UI. I am getting below error when "Send SMS Message" button is pressed.


    Code (CSharp):
    1. 01-06 18:29:31.393: I/Unity(6014): DllNotFoundException: unityandroidsystem
    2. 01-06 18:29:31.393: I/Unity(6014):   at (wrapper managed-to-native) FourthSky.Android.BroadcastReceiver:CreateJavaBroadcastReceiver (intptr)
    3. 01-06 18:29:31.393: I/Unity(6014):   at FourthSky.Android.BroadcastReceiver.Register (System.String[] actions) [0x00000] in <filename unknown>:0
    4. 01-06 18:29:31.393: I/Unity(6014):   at FourthSky.Android.Services.Telephony.SendSMS (System.String phoneNumber, System.String message, System.Action`1 sentCallback, System.Action`1 deliveredCallback) [0x00000] in <filename unknown>:0
    5. 01-06 18:29:31.393: I/Unity(6014):   at AndroidSystemDemoMultipleScreens.TelephonyOnGUI () [0x00000] in <filename unknown>:0
    6. 01-06 18:29:31.393: I/Unity(6014):   at AndroidSystemDemoMultipleScreens.OnGUI () [0x00000] in <filename unknown>:0
     
  29. evandropaulino

    evandropaulino

    Joined:
    Aug 7, 2012
    Posts:
    21
    To Pixel Wrangler - I submitted a new version with Unity 5 compatibility in December, I expect the update will be available soon.

    @Malik Basit - Please, copy the Plugins folder from AndroidSystem folder to Assets folder. This will work
     
  30. Malik-Basit

    Malik-Basit

    Joined:
    Dec 5, 2012
    Posts:
    5
    @evandropaulino I have already done that. Note that I am using Unity 5. Is unity 5 causing this issue?
     
  31. evandropaulino

    evandropaulino

    Joined:
    Aug 7, 2012
    Posts:
    21
    @Malik Basit Yes. Please, inside Plugins/Android folder, create the libs/armeabi-v7a folder structure, and copy unityandroidsystem.so inside.

    I'll submit the update for the package today, so I expect it will be available within some days.
     
  32. evandropaulino

    evandropaulino

    Joined:
    Aug 7, 2012
    Posts:
    21
    People, I submitted the update the wrong way. I'm creating the update the right way, so I think this will take some time.
     
  33. Malik-Basit

    Malik-Basit

    Joined:
    Dec 5, 2012
    Posts:
    5
    @evandropaulino Thanks, i have got it to working. But i am wondering what happens if mobile supports duel sims and it has 2 active networks. Can we send an sms via a specific network? and is there any way to get network operator name ?
     
    Last edited: Jan 8, 2016
  34. evandropaulino

    evandropaulino

    Joined:
    Aug 7, 2012
    Posts:
    21
    @Malik Basit , this is a problem because Android APIs doesn't recognize multiple SIM cards. The only way is to change default operator in system options.
     
  35. fabio1955

    fabio1955

    Joined:
    Nov 11, 2009
    Posts:
    72
    How is going this project? Is it update? I need to read the NFC TAGID and the text. Can the package do this?
     
  36. Philkrom

    Philkrom

    Joined:
    Dec 26, 2015
    Posts:
    89
    Hi, I need to be able to open a scene when scanning an NFC sticker with an android smartphone using a GearVR. Is is possible ? Is the source code provided within the asset ?