【发布时间】:2019-12-11 09:53:00
【问题描述】:
我想从 Unity3d 应用程序在 Android 中启动相机应用程序。我可以通过 Android Studio 构建一个 Android 应用程序来做到这一点。我想为那个android studio项目创建一个jar插件,并通过Unity游戏调用代码。
Unity C# 代码
public class UnityAndroidPluginExample : MonoBehaviour
{
AndroidJavaObject javaClass;
public void CallPlugin()
{
javaClass = new AndroidJavaObject("com.mycompany.pluginexample.CameraPluginClass");
javaClass.Call("LaunchCameraApp");
}
}
Android Studio 代码
package com.mycompany.pluginexample;
import android.content.Intent;
import android.provider.MediaStore;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
public class CameraPluginClass extends AppCompatActivity
{
public void LaunchCameraApp()
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivity(intent);
}
}
我遇到错误
AndroidJavaException: java.lang.ClassNotFoundException:com.mycompany.pluginexample.CameraPluginClass
AndroidJavaException: java.lang.NoClassDefFoundError: 解析失败:Landroidx/appcompat/app/AppCompatActivity
这是适用于 Android 的 Android Studio 代码
btnCaptureImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
});
请帮忙,我被困在这里了。简而言之,我不能调用扩展 AppCompatACtivity 的 Java 类的方法。如果我删除 extends AppCompatActivity 并从 Unity 调用该 Java 类中的一个方法,它会起作用,只有当我使用 extends AppCompatActivty 时,我才能从 Unity 调用该类中的任何方法。我使用的是 Unity 版本 2019.1.7f1。
任何帮助将不胜感激。
【问题讨论】:
-
你的统一版本是什么?
-
@0xBFE1A8,我使用的是 Unity 版本 2019.1.7f1。
标签: c# android android-studio unity3d android-intent