android - 无法在 Unity 上读取 android 意图数据
问题描述
我知道这似乎已经回答了,但它不适用于我,我需要知道是否缺少任何东西。我花了一些时间,但以这种方式读取意图额外数据没有成功。所以我需要知道我是否遗漏了什么。
在没有成功之后,我使用了一种简单的方法。
从android插件我调用它来启动统一应用程序:
Intent intent1 = new Intent();
intent1.setAction("com.Company.Alarm.UnityPlayerActivity");
intent1.setFlags(FLAG_ACTIVITY_NEW_TASK);
//intent1.setType("text/plain");
intent1.putExtra("KEY","This is the text message sent from Android");
context.startActivity(intent1);
在 Unity 上,我使用它来获取数据:
string arguments = "";
AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject intent = currentActivity.Call<AndroidJavaObject>("getIntent");
bool hasExtra = intent.Call<bool>("hasExtra", "arguments");
if (hasExtra)
{
AndroidJavaObject extras = intent.Call<AndroidJavaObject>("getExtras");
arguments = extras.Call<string>("getString", "KEY");
}
text.text = arguments;
Debug.Log("Message Received!!!! :" + arguments);
但是在应用程序启动时,我没有任何价值。请任何人都可以说这里缺少什么或如何解决它?
编辑:
//manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.Company.Alarm" xmlns:tools="http://schemas.android.com/tools" android:installLocation="preferExternal">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<application android:theme="@style/UnityThemeSelector" android:icon="@mipmap/app_icon" android:label="@string/app_name" android:isGame="true" android:banner="@drawable/app_banner">
<activity android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density"
android:hardwareAccelerated="false" android:name="com.Company.x.UnityPlayerActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
<action android:name="com.Company.x.Unity"/>
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
<meta-data android:name="unity.build-id" android:value="0e614110-ed04-4c63-b8d5-f8885587d24c" />
<meta-data android:name="unity.splash-mode" android:value="0" />
<meta-data android:name="unity.splash-enable" android:value="True" />
</application>
<uses-feature android:glEsVersion="0x00020000" />
<uses-permission android:name="android.permission.INTERNET" />
<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.software.leanback"
android:required="false" />
</manifest>
解决方案
推荐阅读
- javascript - 如何使用 C# 从网站读取字符串
- python - 未找到 pip 安装的模块 - macOS
- c# - 方法包含在文本列表字符串类型的字典中
- android - 带有 SurfaceView 的不可见 RelativeLayout
- javascript - 使用 Jquery 或 Javascript 将 LOGICAL 表达式转换为 Json
- javascript - 一行导入多个组件(VueJs)
- android - 如何在 Android TV App 中设置画中画 (PiP) 的位置?
- android - WebSQL vs SQLlite vs IndexDB - 对于 HTML5,哪个数据库更好?
- javascript - 如何在浏览器中调试 Jest 测试?
- ios - 辞职的ipa不要安装在ios设备上