when my program run at 5 line in Unity Test.cs, " AndroidJavaObject jo = jc.CallStatic("instance");", it throw out the exception as described and end up.
Exception:JNI:Init'd AndroidJavaObject with null prt! at UnityEngine.AndroidJavaObject..ctor(IntPtr jobject)(0x00000)in:0
MainActivity.java
public class MainActivity extends UnityPlayerActivity {
private static MainActivity instance;
private static Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MainActivity.instance = this;
context = getApplicationContext();
}
public void InstallAPK(String path)
{
Log.d("debug","InstallAPK path"+path);
File apkFile = new File(path);
if(apkFile.exists())
{
Log.d("debug","InstallAPK!");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(apkFile),"application/vnd.android.package-archive");
context.startActivity(intent);
}
else
{
Log.d("debug","fiald file!");
}
}
public static MainActivity instance()
{
return instance;
}
}
AndroidManifest.xml
Unity Test.cs
void OnGUI()
{
if(GUI.Button(new Rect(10,250,450,100),"Install"))
{
AndroidJavaClass jc = new AndroidJavaClass("com.cmd.kz3d.qihu.MainActivity");
AndroidJavaObject jo = jc.CallStatic("instance");
string path = Application.persistentDataPath+"/test.apk";
Debug.Log(path);
if(!File.Exists(path))
{
Debug.Log("not found");
}
//jc.Call("InstallAPK", path);
jc.Call("InstallAPK", path);
}
}
↧