• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Mizuho · Jun 28, 2012 at 02:06 AM · c#androiddlljava

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() {
         
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

I need add .jar project Unity -1 Answers

How to use Android Api in Unity 1 Answer

DLL works in editor, but gives an exception in Android 0 Answers

Exclude scripts from ios vs android builds? 1 Answer

How to call android.os class from C# code? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges