Log in or register to post comments

Overlaying androi data over QCARUnityPlayer

November 16, 2012 - 8:02am #1

Hello,

I've successfully built a Unity QCAR project and imported it to Eclipse. I want to run the QCARUnityPlayer in a sub view in android so that I can add extra controls and menus using Android. The problem is in my main Activity. When I extend Activity I get the following error:

11-16 15:34:25.931: W/dalvikvm(16057): No implementation found for native Lcom/qualcomm/QCAR/QCAR;.onSurfaceCreated ()V

11-16 15:34:25.961: W/dalvikvm(16057): threadid=11: thread exiting with uncaught exception (group=0x40c631f8)

11-16 15:34:25.961: E/AndroidRuntime(16057): FATAL EXCEPTION: GLThread 612

11-16 15:34:25.961: E/AndroidRuntime(16057): java.lang.UnsatisfiedLinkError: onSurfaceCreated

11-16 15:34:25.961: E/AndroidRuntime(16057): at com.qualcomm.QCAR.QCAR.onSurfaceCreated(Native Method)

11-16 15:34:25.961: E/AndroidRuntime(16057): at com.qualcomm.QCARUnityPlayer.QCARUnityPlayer.onSurfaceCreated(QCARUnityPlayer.java:39)

11-16 15:34:25.961: E/AndroidRuntime(16057): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1446)

11-16 15:34:25.961: E/AndroidRuntime(16057): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)

I've imported all of the necessary libraries but it doesn't work. 
Is there another way to use android controls overlayed over the QCAR activity.
Please help me out I'm in a dead end.

Overlaying androi data over QCARUnityPlayer

June 9, 2013 - 4:41am #17

Hi mr21 I have read your post below of calling the android method from unity.

I have 2 question

1- does it necessary for the method that we are calling from unity to be plcesd in the mainActivity, Or we can make any activity static and call the the function present in those activities? Also i read in different forums about this that you should change the manifest file and make your plugin activity the main activity. Is it necessary to do it or we can call without doing this.

2- my second question is what if I want to call the unity function from android application. Can i do this by inporting the unity project in android and then call the unity scriot function from the android activity.

I have already successfully called a function in unity from android. but in this i made android project the plugin. Now i wan to do it the opposite i.e making the unity project plugin in eclipse.

At i should mention that i am creating a vuforia unity project like your not a simple unity project.

Overlaying androi data over QCARUnityPlayer

May 15, 2013 - 5:35am #16

Overlaying androi data over QCARUnityPlayer

May 15, 2013 - 3:01am #15

AlessandroB you posted:

 

Overlaying androi data over QCARUnityPlayer

Hi, have a look at this Post:
https://ar.qualcomm.at/content/unity-how-can-i-extend-unitys-android-activity

it explains step-by-step what you need to do to get the project up and running in Eclipse and how to add android views on top.

Pay close attention to follow all steps as indicated.

 

 

But the link is not online... Could you pass me the link please?

Because I have the same problem and I don't find the solution....

Thank you!!

Overlaying androi data over QCARUnityPlayer

November 21, 2012 - 6:31am #14

Hey, glad to hear that you found the trick with it!

I am absolutely sure this post will be helpful to other QCAR - Unity developers. 

Overlaying androi data over QCARUnityPlayer

November 21, 2012 - 6:14am #13

Hi I've finally managed to solve this issue as well. The correct methodology is to create a static Activity in your main Android project and call it currentActivity. After this in your oncreate method you set the currentActivity to this the following code demonstrated that:

 

 

public class MainActivity extends QCARPlayerActivity {

public static MainActivity currentActivity;

@Override

   public void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       currentActivity=this;


From your Unity code I've used C# you can call an Android method from the MainActivity by using the following code:


 

AndroidJavaClass jc = new AndroidJavaClass("yourpackagename.youractivity");

AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");

jo.Call("toggleMenu");

 

There are some points that you will need to pay attention in order for everything to work fine:

1) The above code will work only if the method toggleMenu has no parameters. For parameters use the other overloaded form of Call.

2) In android if you're trying to make visual changes to that main UIthread and you try to use findViewById you will gen an exception telling that you can't access elements from the main UI thread. YOu will need to follow this approach:

   public  void toggleMenu () {

     MainActivity.this.runOnUiThread(new Runnable() {

          public void run() {

    View men= findViewById(R.id.outer_list);

    if (men.getVisibility()==View.GONE) {

    men.setVisibility(View.VISIBLE);

    }

    else {

    men.setVisibility(View.GONE);

    }

          }

        });

   }


I hope this helps other users that have faced the same problem.


 

 

 

Overlaying androi data over QCARUnityPlayer

November 20, 2012 - 11:50am #12

Hi, sorry for that but my function is called toggleMenu my mistake while writing the question. Also I've tried it with currentActivity and I've also tried with com.qualcomm.QCARUnityPlayer.QCARUnityPlayer.

I've even tried using the package name of my project (this resulted in an exception). Is there an extra step I should be taking for vuforia? Again thank you for your quick reply.

Overlaying androi data over QCARUnityPlayer

November 20, 2012 - 9:13am #11

Hi, two things you can already try to fix:

1- your function is called "ToggleMenu" but you seem to invoke "toggleMenu" (pay attention to the capital "T");

2- you should replace "MainActivity" with "currentActivity" (as indicated in the documentation) in your GetStatic<> call (as "currentActivity" is not the name of the activity class, but it's a sort of keyword)

 

 

Overlaying androi data over QCARUnityPlayer

November 20, 2012 - 8:39am #10

Hello again, this time I'm trying to call android methods from within unity. The documentation from unity suggests the following code:

			AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
			AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
			jo.Call("Launch");

Since I'm using vuforia I've changed my code to the following:

AndroidJavaClass jc = new AndroidJavaClass("com.qualcomm.QCARUnityPlayer.QCARPlayerActivity");

AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("MainActivity");

jo.Call("toggleMenu");

 

My function is called "ToggleMenu" and I'm using it to show or hide android views when my model appears. This is done in the DefaultTrackableEventHandler of my ImageTarget in Unity.  The Android function resides in the same file as the MainActivity. The application doesn't crash but I don't get any messages in my LogCat so I don''t know what to fix. Can you please point me in the right direction?

Overlaying androi data over QCARUnityPlayer

November 20, 2012 - 2:05am #9

You're welcome.

And thanks for the extra information on Unity raycast.

Overlaying androi data over QCARUnityPlayer

November 20, 2012 - 1:14am #8

Again thank you very much this did the trick. Also I would like to add someething for the other users. If you use a blank layout (linear or something else) over the main view of vuforia the touch events (of unity) still work if you use a raycast from the main AR camera to detect interraction with the collider of your main model.

Overlaying androi data over QCARUnityPlayer

November 20, 2012 - 12:47am #7

I am pasting here the main.xml layout that I inflate and attach under the parent view; it is a linear layout and it shows a textView and a Button both aligned to the right (as an example of how to customize layout positioning, such as center, bottom, top, left/right, etc.):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="right"
    android:orientation="vertical" >
 
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
    
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button" />
</LinearLayout>
 
On the above, I would like to highlight two key elements:
1. in the TextView, I set "android:layout_width="wrap_content"; this is important, because if you were setting it to "fill_parent", then the text would always look as aligned to the left (instead of being aligned to the right as specified in the gravity attribute of the linear layout); the reason is that the "fill_parent" would make the Text to expand to fill the entire row.
 
2. I use the "android:gravity" and not the "android:layout_gravity" in the LinearLayout, so that the gravity is applied to all the elements within the layout (i.e. to the TextView and the Button as well)
 
I hope this helps.
 

Overlaying androi data over QCARUnityPlayer

November 19, 2012 - 10:10am #6

Hi, have you tried with android:gravity instead of android:layout_gravity ?

Overlaying androi data over QCARUnityPlayer

November 19, 2012 - 8:08am #5

I would like to make one more question. The method that you've described works perfectly. Now I've overlayed my Android Content over vuforia content. What I have is a linear layout that takes up 30% of the screen's width while the rest is left for interaction with the Unity 3D model. The problem is that my linear layout is alway loaded on the left side of the screen while I need it to load from the right. I've set the gravity of the layout to Right and I've even triedd experimenting with the margins of the layout but with no effect. Could you please instruct me as to what I can do?

Overlaying androi data over QCARUnityPlayer

November 17, 2012 - 2:05am #4

You're welcome.

Overlaying androi data over QCARUnityPlayer

November 16, 2012 - 1:52pm #3

Thank you very much you have really saved me.

Overlaying androi data over QCARUnityPlayer

November 16, 2012 - 11:43am #2

Hi, have a look at this Post:

https://ar.qualcomm.at/content/unity-how-can-i-extend-unitys-android-activity

it explains step-by-step what you need to do to get the project up and running in Eclipse and how to add android views on top.

Pay close attention to follow all steps as indicated.

 

Log in or register to post comments