androidgoogle-cardboarddaydream

How to call Daydream Activity from a regular 2D Activity


I'm trying to call a VrIntent in Daydream mode. I used DaydreamApi. This is my class:

public class Menu extends Activity {
    private DaydreamApi mDaydreamApi;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main_menu);

      mDaydreamApi = DaydreamApi.create(getApplicationContext());
      startGame(false);
    }

    void startGame(boolean multiplayer) 
    {
        mMultiplayer = multiplayer;

        Intent intent = DaydreamApi.createVrIntent(new ComponentName(this, MainActivity.class));
        if (intent == null) Log.e(TAG,"Error on createVrIntent intent ");
        if (mDaydreamApi == null) {
          Log.w(TAG, "Error on mDayDreamApi");
          startActivity(intent);
        }
        else {
          mDaydreamApi.launchInVr(intent);
        }
    }
}

In my Android.manifest.xml, I added intent filter for DAYDREAM in both activities. Menu is the primary activity started from the launcher. MainActivity is the Daydream one.

<activity
android:name=".Menu"
android:label="@string/app_name"
android:allowBackup="false"
android:screenOrientation="portrait">
<intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.LAUNCHER"/>
    <category android:name="com.google.intent.category.DAYDREAM" />
</intent-filter>
</activity>
<activity
  android:configChanges="orientation|keyboardHidden|screenSize"
  android:enableVrMode="@string/gvr_vr_mode_component"
  android:label="@string/app_name"
  android:name=".MainActivity"
  android:resizeableActivity="false"
  android:screenOrientation="landscape">

  <intent-filter>
    <category android:name="com.google.intent.category.DAYDREAM" />
  </intent-filter>

</activity>

But when I run the application, the activity show this error:

Incompatible app

At the beginning, I had MainActivity as the primary activity and that worked fine. It is only when I try to launch it from the 2D activity that the error shows up.

What am I missing?


Solution

  • You are missing the action as intent-filter for MainActivity. This should do the trick:

    <action android:name="android.intent.action.VIEW"/>
    

    Source: https://github.com/googlevr/gvr-android-sdk/issues/295#issuecomment-261447175