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

Back button event not passed at Android library through Unity and other problems

Discussion in 'Android' started by andreasvourkos, Jan 10, 2014.

  1. andreasvourkos

    andreasvourkos

    Joined:
    Dec 20, 2013
    Posts:
    17
    Hello,

    I am quite new at Unity and I am trying to create a Unity plugin for an Android library and I ma facing the following issues:

    1) I can't find a way to pass the back button event to Android library. What I have managed to do is to pass touch events to the activity on the Android side by setting the following line

    <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />


    at <activity android:name="com.unity3d.player.UnityPlayerProxyActivity" ... > in the AndroidManifest

    However I cannot pass the back button event in a way that I do not have to change the code in the library


    What I do for now in my script is

    public void Update() {

    if(Input.GetKeyDown(KeyCode.Escape))
    Application.Quit();
    }


    However I need the option to pass that back event that I capture, to the library and not handle it at the Unity layer.

    2) I am trying to reference in my script an enum that I have in my Android library.

    For example I have the following enum in a Place.java file


    package com.myapp.constants;

    public enum Place {
    TOP, BOTTOM, RIGHT, LEFT
    }


    and I want to find a way to reference it from my script.

    I tried something like that:

    AndroidJavaClass topPlace = new AndroidJavaClass("com.myapp.constants.TOP");

    but with no luck.

    Can anyone help on those issues? Any help appreciated...
     
    Claytonious likes this.
  2. mushroomrisotto

    mushroomrisotto

    Joined:
    Dec 9, 2013
    Posts:
    24
    If you want to use back button on android u can make a plugin and override Android onBackPressed function to send Unity a message. There are lots of resources that you can find to make a plugin for Unity android, I have also started to write tutorials for that at my blog you can check it out
    http://nevzatarman.wordpress.com/
     
  3. andreasvourkos

    andreasvourkos

    Joined:
    Dec 20, 2013
    Posts:
    17
    Thank you for your response. However this is not what I am asking here. I already have a jar library and I just want to pass the events from unity to that. I do not want to change the code in the jar. Just make the bridge between unity and the library