- Home /
Unity Android action bar callbacks?
I've looked around for the past 2 days for information about how to integrate this, but information is scarce, and Unity being another entity that has to be considered is quickly making this a pain in the ass.
So Unity has a class (`AndroidJNI`), that's supposed to help you with C# to Java cross-language things. That's great and all, but it doesn't do anything Java to C#, which is kinda what you need when the callbacks for the Android action bar are written in Java. I'm not about to write some alternative to the API, so I'm looking for a solution.
So far, the only way I've found to do it is to go from Java -> JNI (becomes header file) -> C++ -> Managed C++ (wrapper) -> C# (compiled as a .netmodule
). That looks like a horribly overblown process for something like this. The process is defined in detail here: http://www.codeproject.com/Articles/13093/C-method-calls-within-a-Java-program.
The only other way I can think of is to somehow work with the mUnityPlayer
object, which doesn't seem very viable since I'm pretty sure the actual meat of the code is packed into a DLL. And decompiling that would yield something great. So great that it's just not worth it.
So does anybody have any ideas on this? Anybody done something like this before? I don't need sample code or anything (would be nice though), but a solid path to follow is a must.
Here is some Java...
package com.lostmystic.dots;
import com.unity3d.player.UnityPlayerActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class GameMenu extends UnityPlayerActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.game_menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// Change journal to back to book here later
return super onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.journal:
return true;
case R.id.puzzle_index:
return true;
case R.id.title_screen:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
And here is the current C# skeleton:
using UnityEngine;
using System.Collections;
/*
* This class is meant to be compiled as a .netmodule dll file for use by Java.
*/
public class JavaExtern {
// ===============================================================================
// = Callback handlers
// ===============================================================================
public void menuJournal() {
}
public void menuBackToBook() {
}
public void menuPuzzleIndex() {
}
public void menuTitleScreen() {
}
}
Answer by Mizuho · Jun 29, 2012 at 07:20 AM
I'm currently solving this by using the GUI when KeyCode.Menu
is pressed. It's not what I'd like to do, but at least it gets the job done. It has the added bonus of porting to iOS really easily.
...Sigh.
Your answer
![](https://koobas.hobune.stream/wayback/20220613073409im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
I need add .jar project Unity -1 Answers
AndroidJavaClass. Call returns null ptr. 1 Answer
How do you access a custom Java class from Unity? 1 Answer
Calling static jar function from Unity3D 0 Answers
Android soft keyboard does not popup 1 Answer