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 Greg 4 · Mar 16, 2011 at 08:40 PM · androidandroidpluginjni

Sending String of Data through JNI to Android Plugin

I have an android plugin (java) that I am using the JNI interface to communicate to, In this plugin I must send a String in a method call and seem to be fudging something up

Code:


Setting up JNI (works for all other functions so my Class Object is valid and working)

meth_SendCommand = JNI.GetMethodID(cls_TactorPlayer,
 "SendCommand", "(Ljava/lang/String;)I");


Sending the Data

String str_command = "Hello Plugin!";

 IntPtr ptr = Marshal.AllocHGlobal(str_command.Length);

 Marshal.Copy(str_command.ToCharArray(), 0, ptr, str_command.Length);

 int returnval = JNI.CallIntMethod(TactorPlayer, meth_SendCommand,ptr);


Capturing the Data within my Java Class

public int SendCommand(String command)
    {
            Log.d("--UNITYJAR-- SendCommand=", String.valueOf(command));
        return 0;
    }


Printing out my intptr that I send shows a valid address But I am guessing the way I Create the intptr to copying the data into it may be my issue

Help is greatly appreiciated, I am running out of ideas!

Thanks

Greg

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
1

Answer by Fenyx4 · Mar 22, 2011 at 04:16 PM

I had good luck using the AndroidJNI to skip the C++ part. With it you could, in a Unity script, do something like this;

//Grab the object AndroidJavaObject javaObject = new AndroidJavaObject("com.myCompany.myStuff.myClass"); javaObject.Call("SendCommand",command);

Sorry if you need the C++ parts and this doesn't apply to you.

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

No one has followed this question yet.

Related Questions

Now that Unity 4.1.2 broke the Android plugin examples, what do you use to learn them? 1 Answer

How can I browse files on Android outside of the Unity App folder? 2 Answers

Getting byte[] or ByteBuffer[] from native Java 1 Answer

Using AndroidJavaObject.CallStatic to retrieve a return value 0 Answers

[Android] Call .jar function on render thread using JNI 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