我需要从我的unity应用程序中通过按下按钮来加载android摄像头应用程序

pgx2nnw8  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(241)

拜托,我至少需要一些经验丰富的用户的反馈。。。这里是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>

当我按下按钮时什么也没发生。。。拜托,帮帮我,也许我做错了什么或者做了一些不合逻辑的事?提前谢谢!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题