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
3
Question by shara · Apr 20, 2011 at 09:05 PM · androidplugincontext

Accessing the Activity Context in Android plugin

Is there a way to access the Activity or Application Context for plugin development?

Say I have a method like this:

public static void myMethod(Context context, String s1, String s2)

How would I call this method from Unity?

Right now I'm trying something like this. The problem is obj_Activity is an Activity type ? How would I pass in the App or Activity Context in this case?

// first we try to find our main activity.. IntPtr cls_Activity = JNI.FindClass("com/unity3d/player/UnityPlayer"); int fid_Activity = JNI.GetStaticFieldID(cls_Activity, "currentActivity", "Landroid/app/Activity;"); obj_Activity = JNI.GetStaticObjectField(cls_Activity, fid_Activity); Debug.Log("obj_Activity = " + obj_Activity);

 AndroidJavaClass myClass = new AndroidJavaClass("com.test.myClass"); 

 myClass.CallStatic("myMethod", 
                         obj_Activity, 
                         new AndroidJavaObject("java.lang.String", "string1"), 
                         new AndroidJavaObject("java.lang.String", "string2"));

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
11
Best Answer

Answer by shara · Apr 20, 2011 at 09:11 PM

Hm I think I figured it out:

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

Comment
Add comment · Show 3 · 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
avatar image lbalasubbaiahapps · Nov 02, 2011 at 11:32 AM 0
Share

hi shara i am newer unity3d developer i need some help from you i followed below documentation but i am not getting properly any help from your side.please help me.i am getting this lines

Unable to find method id for 'Launch' UnityEngine.AndroidJavaObject:Call(String, Object[]) AndroidGui:OnGUI() (at Assets/AndroidGui.cs:16)

file:///Applications/Unity/Unity.app/Contents/Documentation/Documentation/$$anonymous$$anual/Android-Launch%20an%20Android%20Application%20from%20a%20Unity%20Application.html

avatar image Play_Edu · Feb 16, 2016 at 02:50 PM 0
Share

THanks its help me

avatar image meat5000 ♦ · Apr 04, 2016 at 12:53 PM 0
Share

It helps to add a 'setContext' method to your plugin. You can then pass the context data to the plugin after you acquire it using the code you wrote.

I painstakingly managed to write and use a plugin to detect hardware buttons on an Android device. At first I was a bit baffled as to how to retrieve the actual context in use but your snippet helped to demystify that one.

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

Android Manifest Help 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Android plugins and callbacks on non-scripting threads 1 Answer

Soomla Error for android 1 Answer

Application.OpenURL not working 1 Answer


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