无法在Unity上读取android Intent数据

时间:2019-02-08 12:01:04

标签: android unity3d

我知道这似乎已经回答了,但是它对我不起作用,我需要知道是否有任何遗漏。我花了一些时间,但以这种方式读取意图额外的数据没有成功。所以我需要知道我是否缺少什么。

this之后失败之后,我使用了一种简单的方法。

从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>

0 个答案:

没有答案