Android和Unity交互
1.Android Stidio 新建Android项目选择 Empty Activiy2.右键项目选择 New Module——Android Library Package name=Unity项目包名
3.根据业务需求在包名根目录下建立相应的Appliaction/Activity类 并实现onCreate方法 如
-----------------------------------------------------------------------------------------------
ClassMyAppliaction extendsApplication{
@Overridepublic void onCreate() { super.onCreate(); MobSDK.init(this, this.getAppkey(), this.getAppSecret()); UMU3DCommonSDK.init(this, "xxxxxxxxxxxxx", "Umeng", UMConfigure.DEVICE_TYPE_PHONE,""); UMU3DCommonSDK.setLog(true);}
}
---------------------------------------------------------------------------------------------
public class MainActivity extends UnityPlayerNativeActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);}
---------------------------------------------------------------------------------------------
//unity调用的方法public void doRestart(int Ntime){ Intent restartIntent = getPackageManager() .getLaunchIntentForPackage(getPackageName() ); PendingIntent intent = PendingIntent.getActivity(this, 0,restartIntent,0); AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); manager.set(AlarmManager.RTC, System.currentTimeMillis()+Ntime, intent); finish(); android.os.Process.killProcess(android.os.Process.myPid());}}
当需要继承UnityPlayerNativeActivity 时需要引入Unity安装根目录下的classes.jar
Data->PlaybackEngines->androidplayer->Variations->mono->release->classes->classes.jar
-----------------------------------------------------------------------------------------
4.使用Gradle buildlibrary项目
进入项目\build\intermediates\classes\release\包名\
C:/Users/Administrator/AppData/Local/YNote/data/qq34F7EF5B9522FF98678F37FDDDF8FF29/d5580a86ffde4250b78adcb0bd9f7868/078077978_hd.png
删除多余的class文件
然后回到release目录下
打开命令行运行 jar cvf library.jar ./com 生成jar包 围观不明觉厉
页:
[1]