Solving a real-life problem – OMH Maps integration with Signal

Solving

October 6 2023

We often hear questions about how OMH (Open Mobile Hub), now available on GitHub, can provide practical solutions for application developers. Specifically, people want to know how OMH addresses the issue of missing location services on non-GMS (Google Mobile Services) devices. If you’ve been pondering these questions, we have a real-life story that sheds light on how OMH is making a difference for various applications.

Signal - A Privacy-Centric Messaging App

Before diving into the solution, let’s take a moment to introduce Signal. It’s an encrypted messaging app and platform recognized for its unwavering commitment to user privacy and security. Developed by the Signal Foundation, a non-profit organization founded by Moxie Marlinspike and Brian Acton in 2018, Signal has earned a reputation as one of the most secure and privacy-focused messaging apps available today.

While Signal works seamlessly on GMS devices, it faces challenges on non-GMS devices, impacting the user experience with maps, making it less user-friendly and discouraging users from fully enjoying this exceptional service. Google Location fails creating issues when sharing location on non-GMS devices.


OMH’s Solution for Signal

The OMH team took up the task of developing a location/map plugin to address one of these types of challenges. Our goal is to demonstrate to Signal how straightforward it is to make the necessary changes to support a dual solution, catering to both GMS and non-GMS devices.

You can explore the solution on our GitHub repository, where we’ve provided sample code: https://github.com/openmobilehub/Signal-Android

Steps to Overcome Limitations

In this article, we’ll take you through the steps we took to overcome these limitations. We aim to illustrate how simple it is to update the Signal application to offer support for an alternative map option on non-GMS devices, specifically using OpenStreetMap.

In essence, with a single build using OMH, Signal can seamlessly operate on GMS devices, utilizing Google Maps, or function on non-GMS devices, making use of OpenStreetMap. This versatility allows Signal users to enjoy the app regardless of their device’s ecosystem.

We believe this real-life example serves as a testament to OMH’s practicality and its ability to solve real-world problems, ensuring a seamless and secure user experience across a wide range of devices.

Step 1: Add OMH Maps dependencies to app/build.gradle

   dependencies {
      qmsImplementation 'com.openmobilehub.android:maps-api-googlemaps:1.0.1-beta'
      nonamsImplementation 'com.openmobilehub.android:maps-api-openstreetmap:1.0.1-beta'
      singleBuildImplementation 'com.openmobilehub.android:maps-api-googlemaps:1.0.1-beta'
      singleBuildImplementation 'com.openmobilehub.android:maps-api-openstreetmao:1.0.1-beta'
   }

Step 2: Replace Fragment in Layout XML

In your activity_place_picker.xml layout file, where you have defined the map fragment, replace android:name with the OMH MapFragment:

   <fragment
      android:id="@+id/map"
      android:name="com.omh.android.maps.api.presentation.fragments.OmhMapFragment"
      android:layout_width="match_parent"
      android:layout_height="match parent"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout constraintEnd toEndOf="parent"
      app:layout_constraintHorizontal_bias="0.0"
      app:layout constraintStart toStartof="parent"
      app:layout_constraintTop_toTopOf="parent"
      app:layout constraintVertical bias="0.0"
      app:backgroundColor="@color/signal colorBackground"/>

By making this change, you are instructing the layout to use com.omh.android.maps.api.presentation.fragments.OmhMapFragment as the map fragment instead of the Google Maps fragment.

Step 3: Initialize OMH Globally in the ApplicationContext.java

   public class ApplicationContext extends MultiDexApplication implements
   AppForegroundobserver.Listener {
      @Override
      public void onCreate() {
         ...
         OmhUtils.initializeOmhMaps();
         ...
      }
   }

Step 4: Import and initialize OMH Maps Library in PlacePickerActivity.kt

First, in your Signal Android project, you need to import the OMH Maps library. This can be done by adding the necessary import statements at the beginning of your code, just like the code snippet you provided earlier:

   import com.omh.android.maps.api.factories.OmhMapProvider;
   import com.omh.android.maps.api.presentation.fragments.OmhMapFragment;
   import com.omh.android.maps.api.presentation.interfaces.maps.OmhMap;
   import com.omh.android.maps.api.presentation.models.OmhCoordinate;

Ensure that you have added the OMH Maps library to your project’s dependencies.

Step 5: Initialize OMH Components

Inside your Signal PlacePickerActivity.java activity, create an instance of the OmhMapFragment. This fragment will serve as the map view in your activity:

   OmhMapFragment mapFragment = (OmhMapFragment)
   getSupportFragmentManager().findFragmentById(R.id.map);

Make sure you have a layout element with the ID map in your activity’s layout XML file where you want the map to appear.

Step 6: Asynchronously Obtain the Map

To initialize the map, use the getMapAsync method on the mapFragment to get an instance of the OmhMap:

   omhMapView.getMapAsync(omhMap-> {
      // Now you have access to the OMH map instance (omhMap)
      // You can configure and use the map for various purposes here
      OmhMarkerOptions omhMarkerOptions = new OmhMarkerOptions ();
      omhMarkerOptions.setPosition(place);
      omhMap.moveCamera(place, 13);
      omhMap.addMarker(omhMarkerOptions);
      omhMap.setOnMapLoadedCallback(() -> omhMap.snapshot(bitmap -> {
         future.set(bitmap):
         frameLayout.setVisibility(View.GONE);
         omhMarView.onPause():
         omhMapView.onStop();
         omhMapView.onDestroy():
      }));
   });

Inside the callback, omhMap is the reference to your OMH map, and you can configure it as needed.

Step 7: Configure and Use OMH Map

Now that you have the omhMap instance, you can configure it for your specific needs. This may include setting up map markers, enabling user location, adding event listeners, and more, depending on your app’s requirements.

   omhMap.setMyLocationEnabled(true);
   // Add markers, set camera position, and perform other map-related operations


And that’s it! With these steps, you’ve enabled Signal to use OMH Maps. You can now customize the map to provide location-related functionality in your own app.

OMH

Fork our samples and try them yourself.

Thank you for reading this OMH SDK article! We hope that you are enjoying these series and learning new things. We are open to any open-source contributors of this project, please contact us at contact@openmobilehub.com if you are interested in joining the unified app development revolution now!