【问题标题】:Launching an external android app in C#/Unity在 C#/Unity 中启动外部 android 应用程序
【发布时间】:2014-10-18 08:06:17
【问题描述】:

所以我已经被这个问题困住了好几天了。我已经将 Unity 与 Eclipse IDE 集成在一起,我可以完美地构建和部署项目。但是,我试图在 java 端启动一个基本 Intent 并在 Unity/C# 端触发它。

这是我的 Java 端代码:

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import com.unity3d.player.UnityPlayerNativeActivity;

public class AppLauncher extends UnityPlayerNativeActivity 
{

    public  Intent myIntent;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        //Assuming that we want to launch the browser to browse a website
        Uri uri = Uri.parse("http://www.google.com");
        myIntent= new Intent(Intent.ACTION_VIEW, uri);
    }

    public void Trigger()
    {       
        startActivity(myIntent);

    }
}

这是当 C# 触发器被触发时 logcat 抛出的错误:

这是我在 if it 的 C# 方面的代码:

if(s[0].Equals("Spr"))
{
    print("Launched");
    AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
    jo.Call("Trigger");
}

这是当 C# 触发器被触发时 logcat 抛出的错误:

AndroidJavaException: java.lang.NoSuchMethodError: no method with name='Trigger' signature='()V' in class Lcom/unity3d/player/UnityPlayerNativeActivity;

我尝试通过在 C# 脚本中传递自定义签名以及 Trigger 方法名称来解决问题,我尝试扩展标准 UnityPlayerActivity 等...我尝试了数小时的东西,但我似乎无法解决这个问题。

非常欢迎任何帮助!

【问题讨论】:

  • 有人吗?真的需要帮助!

标签: java c# android unity3d


【解决方案1】:

您确定您的活动已创建吗?你真的需要延长活动吗?我会尝试这样的事情:

Java:

package my.package;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

public class AppLauncher 
{
    public static void Trigger()
    {     
        //Assuming that we want to launch the browser to browse a website
        Uri uri = Uri.parse("http://www.google.com");
        Intent myIntent= new Intent(Intent.ACTION_VIEW, uri);  
        startActivity(myIntent);
    }
}

C#:

AndroidJavaObject jo = new AndroidJavaObject("my.package.AppLauncher");
jo.CallStatic("Trigger");

【讨论】:

  • 如何将变量传递给方法?我尝试,(方法,“mystring”)但java引擎认为第二个var用于方法的签名..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多