I am trying to get the url for the intent. I am trying to do getIntent().getData() in unity.
The intent is always null, so the call intent.Call(“getData”); always fails.
There are other threads about that but they are all old and the problem is a little different, so I think now there should be an easy way to make getIntent().getData().
According to the documentation of getData (see link here)
This means that this method can return null. AFAIK, there’s no way to represent a null response from a method using Unity’s AndroidJavaObject or AndroidJavaClass - in case a null is returned, the code will throw an exception (you cannot initialize a AndroidJavaObject class with a null reference).
You can see this also when peeking into the constructor of this class:
Before trying to solve this particular scenario, what are you trying to achieve exactly ?
From what i can think of, you have 2 options:
Create your own .JAR library with your own methods. These will call getIntent() and getData(), do all the null checks and return the proper data (never return null).
Skip AndroidJavaObject and work at the AndroidJNI classes layer - create your own JNI class definitions and method signatures, and invoke them to retrieve an IntPtr response (then you can check if it’s null or not).
Frankly i think that option #1 is better and much easier (create a simple JAR with a few utility methods and invoke those from Unity). I’ve never tried option #2 (it should work only in theory, but involves a bunch of hackery using reflection, since most of what you need is not exposed as public).
I may be wrong and there may be other options here, maybe @Yury-Habets can advise
@liortal
Thank you for your detailed reply.
Now I know that the exception I get is because getData returns null.
I will give option 1 and 2 a try.
I am using a native library where I have to call a function passing the getIntent()->getData() parameter to it.
I thought it’s easier to call it from inside c#.
I got the same problem. I think it’s a bug in the code posted above. activityObject.GetRawObject() should be intent.GetRawObject() so the code should read;