我做错了什么? (编写虚拟活动并通过c#调用它)

时间:2015-10-31 11:41:53

标签: java c# android unity3d

我读过Thread“More Google OBB drama”,并看到:“在主要活动的暂停/恢复循环期间,OBB被添加到”搜索路径“.Application.dataPath将指示它是否已挂载。 因此,如果未挂载,则需要触发暂停/恢复周期(最简单的方法是初始化“虚拟”活动,只能从eriQue立即返回。所以我试试这个,但我认为我做错了,因为我非常非常非常喜欢java和android开发(活动)。这是我的代码:

public class ReloadObbActivity extends Activity {

private Intent myIntent;


@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    myIntent= new Intent(this,ReloadObbActivity.class);
    finish();
}

public void Launch()
{
    startActivity(myIntent);
}

}

 public static void RunDummyActivity()
{
    using (AndroidJavaClass unity_player = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
    {

        var jc = new AndroidJavaClass("mycompany.com.reloadobbplugin.ReloadObbActivity");
        jc.Call("Launch");



        if (AndroidJNI.ExceptionOccurred() != System.IntPtr.Zero)
        {
            Debug.LogError("Exception occurred while attempting to start DownloaderActivity - is the AndroidManifest.xml incorrect?");
            AndroidJNI.ExceptionDescribe();
            AndroidJNI.ExceptionClear();
        }
    }
}

所以它不起作用,没有例外

1 个答案:

答案 0 :(得分:1)

我知道我哪里错了。

public class DummyActivity extends Activity
{
  protected void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    finish();
  }

  public static void Launch(Activity activity)
  {
    Intent myIntent = new Intent(activity, DummyActivity.class);
    activity.startActivity(myIntent);
  }
}

和c#代码:

public static void RunDummyActivity()
        {
            using (AndroidJavaClass unity_player = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
            {
                AndroidJavaObject current_activity = unity_player.GetStatic<AndroidJavaObject>("currentActivity");

                var jc = new AndroidJavaClass("com.exampleCompany.DummyActivity");
                jc.CallStatic("Launch", current_activity);
            }
        }

将java代码导出到jar文件并将其放在Plugins / Android中。 并且不要忘记添加此活动的行以显示。