【发布时间】:2021-04-22 07:41:37
【问题描述】:
拜托,我至少需要一些更有经验的用户的反馈... 这里是java类:
package com.example.launchcameraplugin;
import android.content.Intent;
import android.provider.MediaStore;
import androidx.appcompat.app.AppCompatActivity;
public class LoadCameraPlugin extends AppCompatActivity
{
public void LaunchCameraApp(final ILoadCameraPluginCallback callback)
{
callback.LaunchCameraApp();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivity(intent);
}
}
这里界面:
package com.example.launchcameraplugin;
public interface ILoadCameraPluginCallback
{
void LaunchCameraApp();
}
这里是C#回调代码:
public interface ILoadCameraPluginCallback
{
void LaunchCameraApp();
}
public class LoadCameraPluginCallback : AndroidJavaProxy, ILoadCameraPluginCallback
{
public event System.Action launchCameraApp;
public LoadCameraPluginCallback() :
base("com.example.launchcameraplugin.ILoadCameraPluginCallback") { }
public void LaunchCameraApp()
{
launchCameraApp?.Invoke();
}
}
这里是调用java代码的C#代码:
public class LoadCameraPlugin : IDisposable
{
private AndroidJavaObject plugin;
private LoadCameraPluginCallback callback;
public LoadCameraPlugin()
{
plugin = new AndroidJavaObject("com.example.launchcameraplugin.LoadCameraPlugin");
callback = new LoadCameraPluginCallback();
}
public void Start()
{
plugin.Call("LaunchCameraApp", callback);
}
public void Dispose()
{
if(plugin != null)
{
plugin.Dispose();
}
plugin = null;
}
}
在这里,我通过按钮加载 C# 函数,该函数加载 java 代码,在我的智能手机上加载相机应用程序:
public class StartPluginToLoadCameraByButton : MonoBehaviour
{
public Button button;
public GameObject ButtonOjbect;
private LoadCameraPlugin plugin;
private void Start()
{
plugin = new LoadCameraPlugin();
button = GetComponent<Button>();
button.onClick.AddListener(StartPlugin);
}
public void StartPlugin()
{
plugin.Start();
}
}
我用android studio打开了我的apk文件,找到了AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="0.1"
android:installLocation="2"
android:compileSdkVersion="29"
android:compileSdkVersionCodename="10"
package="com.AlexCompany.MyOS"
platformBuildVersionCode="29"
platformBuildVersionName="10">
<uses-sdk
android:minSdkVersion="24"
android:targetSdkVersion="29" />
<supports-screens
android:anyDensity="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true" />
<uses-feature
android:glEsVersion="0x20000" />
<uses-permission
android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.VIBRATE" />
<uses-permission
android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.front"
android:required="false" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen.multitouch"
android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen.multitouch.distinct"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.ar"
android:required="true" />
<uses-feature
android:name="com.google.ar.core.depth"
android:required="true" />
<queries>
<package
android:name="com.google.ar.core" />
</queries>
<application
android:label="@ref/0x7f060005"
android:icon="@ref/0x7f040000"
android:banner="@ref/0x7f010000"
android:isGame="true"
android:extractNativeLibs="true">
<activity
android:theme="@ref/0x7f070001"
android:name="com.unity3d.player.UnityPlayerActivity"
android:launchMode="2"
android:screenOrientation="0"
android:configChanges="0x40003fff"
android:hardwareAccelerated="false">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
<category
android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
<meta-data
android:name="unityplayer.UnityActivity"
android:value="true" />
</activity>
<meta-data
android:name="unity.splash-mode"
android:value="0" />
<meta-data
android:name="unity.splash-enable"
android:value="true" />
<meta-data
android:name="unity.build-id"
android:value="faa3eba5-4901-4a5e-8e8f-ed461bf7adc5" />
<meta-data
android:name="unityplayer.SkipPermissionsDialog"
android:value="true" />
<meta-data
android:name="com.google.ar.core"
android:value="required" />
<meta-data
android:name="com.google.ar.core.min_apk_version"
android:value="210210000" />
<activity
android:theme="@ref/0x0103023a"
android:name="com.google.ar.core.InstallActivity"
android:exported="false"
android:excludeFromRecents="true"
android:launchMode="1"
android:configChanges="0x4a0" />
</application>
</manifest>
当我按下按钮时,什么也没有发生......请帮忙,也许我做错了什么或做一些不合逻辑的事情?提前谢谢!
【问题讨论】:
-
你好阿米特莱因!谢谢您的回答!我在不使用插件的情况下解决了我的问题))再次感谢您!祝你在未来的项目中好运!
-
请在答案中写下您的答案,以便将来遇到此问题的任何人也能够解决它
-
好的,我今天就做这个!
=) -
你也是!=) 你很善良!这是罕见的))保持不变)
标签: java c# android unity3d plugins