- INTRODUCTION
- PRE-REQUISITES
- GETTING STARTED
- Obtaining HERE Credentials for Your App
- Integrating Google Play Services into Your App
- Adding the HERE Mobility SDK as a Dependency
- Enabling Multidex
- Setting the Java Language Version
- Configuring Your
AndroidManifest.xmlFile - Creating an
ApplicationClass - Initializing the HERE Mobility SDK
- Authenticating your app
- Using the HERE Sandbox Platform
- Update gms security provider (for Android API <= 19)
- 3rd Party dependencies
- TUTORIAL
- API REFERENCE
The HERE Mobility SDK helps you create apps with rich and dynamic mobility functionality. The SDK accesses the HERE Mobility Marketplace, a centralized platform for managing mobility data using intelligent algorithms.
The HERE Mobility SDK contains 2 packages:
- Mobility Demand
- Map Services
You can use any combination of these packages. The only requirement is that you use the same version for all of them.
The Mobility Demand package allows your app to request and manage passenger rides anywhere in the world, supplied with the HERE Mobility Marketplace. This includes requesting ride offers, booking and canceling rides, and updating a ride’s status.
The Map Services package provides comprehensive map capabilities, including:
- Searching for locations by address or name
- Dynamic rendering of map display
- Point-to-point route calculation
Try out our sample apps:
The HERE Mobility SDK version 2.0.76 supports Android version 4.1 (API level 16) or later.
Also the SDK requires androidx components.
To use the HERE Mobility SDK, you'll need App ID key and App secret key values. To get new app keys, sign up first to Here Mobility Developer Zone and then register your app using the app bundle id/package name.
Set up Google Play Services in your app and add the play-services-location module as a dependency.
In your project’s root build.gradle, add the following to your repositories section:
repositories{
...
maven{
url "https://mobility.bintray.com/sdk"
}
}In your app module’s build.gradle, add the following lines to your dependencies section (only include the modules you want):
dependencies{
...
implementation "com.here.mobility.sdk:demand:2.0.76"
implementation "com.here.mobility.sdk:map:2.0.76"
}To use the HERE Mobility SDK, you will need to enable multidex for your app.
If you’re using Java 7, add the following to the Android section of your app module’s build.gradle:
android{
...
compileOptions{
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_8
}
}If you’re using Java 8, add the following to the Android section of your app module’s build.gradle:
android{
...
compileOptions{
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}Add the following lines to the <application> section of your AndroidManifest.xml file (inserting your actual API key in place of YOUR_API_KEY):
<meta-data android:name="com.here.mobility.sdk.API_KEY" android:value="YOUR_API_KEY"/> Alternately you may set the API key in code. see 3.8. below
To allow your app to access location information and to enable HERE Mobility SDK operation, add the following permissions to your AndroidManifest.xml file:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>Note: If your targetSdkVersion is 23 or higher, you must also ask the user for location permissions at runtime.
If you already have an Application class, you can skip this step. Otherwise, refer to android documentation for instructions.
In your Application class’ onCreate() method, add Sdk.init(this), as follows:
public void onCreate(){
super.onCreate();
MobilitySdk.init(this);
if (MobilitySdk.getInstance().isHereAgentProcess()){
return;
}
// The rest of your code, if any, here
}If you wish to set your API key in code instead of in manifest, you should call
MobilitySdk.init(this, YOUR_API_KEY);Instead.
In order to make Here SDK API calls, we must validate your app by signing your App Key with the Secret Key provided to you as part of your app registration process. You may use the Hash app level authentication to get access for : requestRideOffers, getVerticalsCoverage requests only. The recommended procedure is:
- Hold your secret key in the backend server of your app.
- Generate the hash in your app's backend.
- Pass the hash to the client.
Then pass it to the SDK following these steps:
MobilitySdk.getInstance().authenticateApplication(
ApplicationAuthInfo.create(hash, currentTimeSec));The currentTimeSec parameter tells us when this authentication hash was created (in seconds, since Epoch) .
Below is example Android code that uses the Secret Key to generate a signed hash:
@NonNull
private static String signedHash(@NonNull String apiKey, // Your API Key
long currentTimeSec, // The creation time of the Application auth info in seconds since epoch
@NonNull String secretKey){ // Your Secret Key
try{
Mac mac = Mac.getInstance("HmacSHA384");
Charset ascii = Charset.forName("US-ASCII");
mac.init(new SecretKeySpec(secretKey.getBytes(ascii), mac.getAlgorithm()));
String apiKey64 = Base64.encodeToString(apiKey.getBytes(ascii), Base64.NO_WRAP);
String data = apiKey64 + "." + currentTimeSec;
byte[] rawHash = mac.doFinal(data.getBytes(ascii));
// Encode into a hexadecimal string
StringBuilder hash = new StringBuilder();
for (int i = 0; i < rawHash.length; ++i){
hash.append(String.format("%02x", rawHash[i]));
}
return hash.toString();
} catch (NoSuchAlgorithmException | InvalidKeyException e){
throw new IllegalStateException("HmacSHA384 and US-ASCII must be supported", e);
}
}Note: For reference on how to generate a signed hash (given the secret key) please check Android sampleApp project (function appLogin in AuthUtils).
We require a second level of authentication for booking a ride ,receiving ride updates, cancellation etc.. (all rides related demand API calls) ,verifying that the phone number or email provided by your users is valid. Access to the Maps module API doesn’t require phoneor email verification Phone number or email verification is done in 3 steps:
boolean isUserVerified = MobilitySdk.getInstance().isUserVerified();Phone verification:
ResponseFuture<Void> futureVerification =
MobilitySdk.getInstance().sendVerificationSms(userPhoneNumber);
futureVerification.registerListener(phoneVerificationResponseListener);Email verification:
ResponseFuture<Void> futureVerification =
MobilitySdk.getInstance().sendVerificationEmail(userEmail);
futureVerification.registerListener(emailVerificationResponseListener);Verify phone number pin:
ResponseFuture<Void> verifyUserPhoneFuture =
MobilitySdk.getInstance().verifyUserPhoneNumber(phone, code);
verifyUserPhoneFuture.registerListener(verifyPhoneFutureResponseListener);Verify email pin:
ResponseFuture<Void> verifyUserEmailFuture =
MobilitySdk.getInstance().verifyUserEmail(email, code);
verifyUserEmailFuture.registerListener(verifyEmailFutureResponseListener);You can use the HERE Mobility Sandbox platform to develop and test your app’s functionality without calling the production platform. Requests to the sandbox environment are ephemeral (do not actually affect the real world).
The HERE Mobility service directs your app’s calls to the sandbox or production environment according to the API key you provide.
Here mobility SDK uses TLS 1.2.
If your app is using android API version <= 19 the TLS security provider might not be up-to-date, thus all network requests will fail.
Update the security provider using the following link: https://developer.android.com/training/articles/security-gms-provider
For Tutorial HERE Mobility Tutorial.
For detailed information about HERE Mobility SDK functions, please refer to the HERE Mobility API reference.