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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Writing android native plugin

Discussion in 'Scripting' started by startas, Jun 24, 2015.

  1. startas

    startas

    Joined:
    Nov 14, 2014
    Posts:
    102
    So, i want to write android native plugin to get some stuff from android, like system uptime and so on. I was using this tutorial http://www.lorenzonuvoletta.com/how-to-create-a-native-android-plugin-for-unity/ , and it worked good, but this tutorial is pointless as many others, because it doesnt really use anything from android, its just yet another tutorial done in wrong way. I wanted to get some stuff from android, so i imported android.os.SystemClock to my java android plugin, and tried to return SystemClock.elapsedRealtime(), but it didnt do anything. Maybe someone know how to write android native plugins in java for unity or what is wrong with that tutorial ?
     
  2. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    What do you mean "it didn't do anything"? Can you elaborate?... That tutorial is perfectly fine. All it is showing is how to call Unity functions from Java and vice-versa.
     
  3. startas

    startas

    Joined:
    Nov 14, 2014
    Posts:
    102
    As is written in tutorial, example just sends random number to java plugin, plugin then calls method from unity and it return that random number, and that thing worked good, but when i changed return value in java plugin, it didnt return anything.

    Edit : after like 10 more tests and recompiles, it started working. I dont know what happened, but now it works and java plugin returns value from android native function.
     
  4. thy3s

    thy3s

    Joined:
    Feb 14, 2014
    Posts:
    7