问题
i want use this java code to get uri data in unity i write this script code to call this method , but not work
*java
public String GetUri(){
Intent intent = getIntent();
Uri intentData = intent.getData();
return intentData.getQueryParameter("token");
}
*c#
TextShow.text += ajc.Call<string>("GetUri");
After many tests , i find only static method can call in unity
like this
*java
public static String DoSthInAndroid3()
{
return "33333";
}
*c#
TextShow.text += ajc.Call<string>("DoSthInAndroid3");
i try Non-static method , but not work
public String DoSthInAndroid3()
{
return "33333";
}
TextShow.text += ajc.Call<string>("DoSthInAndroid3");
how to use android Plugin to get the uri data? the getIntent() seem cant call in static method , how do i get it ?
------------update-----------------
java
package com.s.mylibrary;
import android.net.Uri;
import com.unity3d.player.UnityPlayerActivity;
public class AndroidPlugin extends UnityPlayerActivity {
public static String GetString(){
return"TestThisPlugin";
}
public String GetUri(){
Uri intentData = getIntent().getData();
return intentData.getQueryParameter("token");
}
}
c#
void GetAndroidUri()
{
var ajc = new AndroidJavaClass("com.s.mylibrary.AndroidPlugin"); //(1)
TextShow.text += ajc.CallStatic<string>("GetString");
TextShow.text += ajc.CallStatic<string>("GetUri");
TextShow.text += ajc.Call<string>("GetUri");
}
AndroidManifest
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="justlovepaohuzi" android:host="hmok" android:pathPrefix="/UserToekn"/>
</intent-filter>
html
<a href="justlovepaohuzi://hmok/UserToekn/?token=123456999"> Open3 </a>
-----------------update---------------
i fix method name and try new Print code, i find i still can't get non-static method , not have error message , but still different from expectation
java
package com.s.mylibrary;
import android.net.Uri;
import com.unity3d.player.UnityPlayerActivity;
public class AP extends UnityPlayerActivity{
public static String GetString(){
return "TestThisAP";
}
public String GetString2(){
return "AAAAAA";
}
public String GetUri(){
Uri uri = getIntent().getData();
return uri.getQueryParameter("token")+"XDDX";
}
}
c#
void GetAndroidUri()
{
var ajc = new AndroidJavaClass("com.s.mylibrary.AP");
TextShow.text += ajc.CallStatic<string>("GetString");
TextShow.text += ajc.Call<string>("GetString2");
TextShow.text += ajc.Call<string>("GetUri");
TextShow.text += "Last";
}
relult string
expected "TestThisAPAAAAAA(token)XDDXLast"
relult "TestThisAPLast"
回答1:
I finally found a solution in this article
enter link description here
来源:https://stackoverflow.com/questions/52367035/how-to-call-non-static-method-from-unity-android-plugin