言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

AndroidJavaObject.Call

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public function Call(methodName: string, params args: object[]): void;
public void Call(string methodName, params object[] args);
public def Call(methodName as string, *args as object[]) as void

Parameters

methodName 呼び出する特定のメソッド名
args メソッドに渡す引数の配列

Description

staticでないJava メソッドを呼び出します

戻り値の方が 'void' のメソッドを呼び出すには通常のメソッドを使用します。

	// Create a android.content.res.Configuration object and call setToDefaults.
	function Start() {
		var jo = new AndroidJavaObject("android.content.res.Configuration");
		jo.Call("setToDefaults");
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Start() {
        AndroidJavaObject jo = new AndroidJavaObject("android.content.res.Configuration");
        jo.Call("setToDefaults");
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def Start() as void:
		jo as AndroidJavaObject = AndroidJavaObject('android.content.res.Configuration')
		jo.Call('setToDefaults')

public function Call(methodName: string, params args: object[]): ReturnType;
public ReturnType Call(string methodName, params object[] args);
public def Call(methodName as string, *args as object[]) as ReturnType

Parameters

methodName 呼び出する特定のメソッド名
args メソッドに渡す引数の配列

Description

オブジェクト上のJavaメソッドを呼び出します

戻り値の型が void でないメソッドを呼び出す場合はジェネリックメソッドを使用します。

	// Create a java.lang.String object holding the string "some string",
	// and retrieve it's hash code.
	function Start() {
		var jo = new AndroidJavaObject("java.lang.String", "some string");
		var hash = jo.Call.<int>("hashCode");
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Start() {
        AndroidJavaObject jo = new AndroidJavaObject("java.lang.String", "some string");
        int hash = jo.Call<int>("hashCode");
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	def Start() as void:
		jo as AndroidJavaObject = AndroidJavaObject('java.lang.String', 'some string')
		hash as int = jo.Call[of int]('hashCode')