Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 FDNYRES1CUE · Jul 28, 2012 at 06:19 PM · androidvariablesjavaclasses

Accessing variables from android java objects

Hi, I am writing a C# script for a plugin I am writing in which needs to get a string from an android java object. I can call functions and stuff using what I have right now but anytime I go to get a variable stored in the object it comes back blank. I have been using the AndroidJavaObject.GetStatic to try to call variables. I am not sure if I am using this right or not but here is my code...

C# Unity Side

alt text

using UnityEngine; using System.Collections; public class FacebookInt : MonoBehaviour {

private AndroidJavaClass FBses; private AndroidJavaObject jo; public string FbEmail; public string FbName; public string FbID; bool alreadychecked=false; public bool logresp= false;

// Use this for initialization void Start () { // create our new actvity if (Application.platform==RuntimePlatform.Android) {FBses=new AndroidJavaClass("com.codestormstudios.seeitextensions.Extensions"); jo= FBses.GetStatic("currentActivity"); } }

void update () {

// use this only if were on login screen if (Application.loadedLevelName=="StartScreen") {FBLoginListener ();}

}

void OnGUI () {

GUI.Label(new Rect(0,0,300,100),FbEmail); }

public void FBLogin () {

if (Application.platform==RuntimePlatform.Android) { FBses.CallStatic ("facebooklaunch",0); }

}

// checks to see if we have completed sign in process. if so commence login sequence public void FBLoginListener () { if (!(alreadychecked)) { Debug.Log("Got here FBLoginListener: failed"); logresp=jo.GetStatic("FacbookLoginResult"); if (logresp) { Debug.Log("Got here FBLoginListener: sucess"); FbID=jo.GetStatic("useid"); FbEmail=jo.GetStatic("email"); FbName=jo.GetStatic("username");

alreadychecked=true; }

else { FbID=""; FbEmail=""; FbName=""; } } }

Here is my android side of things... alt text

package com.BlockedName.BlockedName; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.widget.Toast; import com.unity3d.player.UnityPlayer; import com.unity3d.player.UnityPlayerActivity;

public class Extensions extends UnityPlayerActivity{

// class variables /////////////////////////////////// // Activity result function static int resultcheck; static int faceval; // Facebook vars public static String useid=""; public static String email="boo"; public static String username=""; public static Boolean FacbookLoginResult=false; // toast function public static String ToastVal ="test";

///////////////////////////////////////////////////// @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); unitytoast ();

}

public static void unitytoast () { Toast workingtoast=Toast.makeText(UnityPlayer.currentActivity.getApplicationContext(), ToastVal, Toast.LENGTH_LONG); workingtoast.show();

}

// Launcher functions

public static void facebooklaunch ( final int functionswitch) // send which Facebook function we want to use

{ resultcheck=1; faceval=functionswitch; Intent facebookint; facebookint = new Intent(UnityPlayer.currentActivity.getApplicationContext(),FacebookInt.class); // input the function value facebookint.putExtra( "functswitch" , functionswitch); final int result=1;

UnityPlayer.currentActivity.startActivityForResult(facebookint,result); }

@Override public void onActivityResult (int requestCode,int resultCode,Intent data) { super.onActivityResult(requestCode, resultCode, data);

switch (resultcheck) { case 1: // facebook function switch (faceval) { case 0:// login FacbookLoginResult=data.getBooleanExtra("FacbookResult", FacbookLoginResult); if (FacbookLoginResult==true) { useid=data.getStringExtra("useid"); email=data.getStringExtra("email"); username=data.getStringExtra("username"); Log.d("gotvals",useid); Log.d("gotvals",email); Log.d("gotvals",username); }

else { useid=""; email=""; username=""; }

break; }

break; }

} // class continues... }

snap1.jpg (101.1 kB)
snap2.jpg (61.3 kB)
Comment
Add comment · Show 1
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
avatar image FDNYRES1CUE · Jul 28, 2012 at 06:22 PM 0
Share

sorry the code is co$$anonymous$$g out weird. Let me try to fix it.

1 Reply

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

Answer by FDNYRES1CUE · Jul 29, 2012 at 12:26 AM

I figured it out. It ended up that I just used unitysendmessage() from the native android side of things. I still world like to understand what the GetStatic functions do to vars.

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Importing a Unity3D scene into Android Fragment 3 Answers

How put Android native code into c# unity 2 Answers

Integration of Java,C++,C# in Unity 0 Answers

Unable to Convert classes into dex Format 1 Answer

Calling static jar function from Unity3D 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