Open Google Maps navigation in Picture and Picture Mode

Viewed 325

I have a simple intent to run google maps navigation - it works really well. It automatically switches to bicycle mode and does not require any confirmation from user, just starts navigating. My code looks like this:

    try {
        Uri gmmIntentUri = Uri.parse("google.navigation:q=" + lastPoint.latitude + "," + lastPoint.longitude + "&mode=b");
        Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
        mapIntent.setPackage("com.google.android.apps.maps");
        startActivity(mapIntent);
    } catch (Exception e) {
        e.printStackTrace();
    }

Now, how can I modify this intent to run navigation in picture-in-picture mode by default (ofc it must be available in the system and enabled for google maps app)? My app does not use PiP by itself, if it's your concern.

1 Answers

You can refer this official guide PiP Support

As shown in the article, First you may need to declare PiP support in androidmanifest.xml like this

<activity android:name="VideoActivity"
android:supportsPictureInPicture="true"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"

and then

@Override
public void onActionClicked(Action action) {
  if (action.getId() == R.id.lb_control_picture_in_picture) {
    getActivity().enterPictureInPictureMode();
    return;
  }
  ...
}
Related