unity与Android相互调用

原地址:http://www.cnblogs.com/ayanmw/p/3727782.html

现在unity 导出的android客户端需要调用 Android 的支付SDK,但是unity与android应该如何互相调用呢???

经过百度 谷歌.终于找到方法,明白大概原理了.

 

重要参考资料:

Unity3D研究院之打开Activity与调用JAVA代码传递参数(十八)

 

下面说几点我犯的错误:

1:Android工程 导入unity-class.jar后,不要设置 setContentView,不要设置layout,因为继承了unityPlayerActivity,我想unity已经设置过了的,如果你在设置,那么就没法调用unity的场景了。

复制代码
package com.xys;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.unity3d.player.UnityPlayerActivity;

public class UnityTestActivity extends UnityPlayerActivity {
    /** Called when the activity is first created. */

    Context mContext = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      // setContentView(R.layout.main); mContext = this; } public void StartActivity0(String name) { Intent intent = new Intent(mContext,TestActivity0.class); intent.putExtra("name", name); this.startActivity(intent); } public void StartActivity1(String name) { Intent intent = new Intent(mContext,TestActivity1.class); intent.putExtra("name", name); this.startActivity(intent); } }
复制代码

unity其实也就是这个activity,不过是android工程继承了这个activity而已。

AndroidManisest.xml

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

 </intent-filter>

还是这个主Activity。

 

2.安装APK的时候,出现错误:INSTALL_FAILED_CONTAINER_ERROR

http://blog.sina.com.cn/s/blog_4b93170a0102dwzq.html

当Unity工程使用android:installLocation="preferExternal" 时,某些时候会出现

Installation error: INSTALL_FAILED_CONTAINER_ERROR
解决办法:
修改为android:installLocation="auto" 即可

 

 

转载请注明出处:http://www.cnblogs.com/ayanmw 我会很高兴的!

------------------------------------------------------------------------------------------------

一定要专业!本博客定位于ArcGIS开发,C语言,C++语言,Java语言,Android开发和少量的Web开发,之前是做Web开发的,其实就是ASP维护,发现EasyASP这个好框架,对前端后端数据库 都很感觉亲切啊。.

posted @ 2014-07-10 16:27  ing...  阅读(905)  评论(0编辑  收藏  举报