0

I know this is seems like already answered, but its not working with me and I need to know if anything is missing. I spent some time but I had no success reading intent extra data this way. So I need to know if I'm missing something.

I' using a simplistic approach after not having success following this.

From android plugin I'm calling this to launch unity app:

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);

And on Unity I'm using this to get the data:

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);

But on app launch I got no value. Please can anyone say what is missing here or how to fix it?

edit:

    //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>
Rifat
  • 1,700
  • 3
  • 20
  • 51
  • 1
    Check if your manifest has `forwardtodalvik` set to true, you would need to set it to false. – karan Feb 08 '19 at 12:16
  • sorry I cant find where to put that. but in both plugin and Unity manifest nothing mentioned as 'forwardtodalvik', and google has only four results which also doesnt show that in manifest, can you please say where to put that value? – Rifat Feb 08 '19 at 12:33
  • 1
    it must be in android project manifest file. – karan Feb 08 '19 at 12:35
  • added the manifest but theres nothing as 'forwardtodalvik'. also tried "" but no success. – Rifat Feb 08 '19 at 13:03
  • try with this `unityplayer.ForwardNativeEventsToDalvik` – karan Feb 08 '19 at 13:07
  • If that value is set to false will touch inputs work? – Rifat Feb 08 '19 at 13:28

0 Answers0