Integrate Hotline SDK (Using Gradle)
Add the maven URL to the root build.gradle (project/build.gradle)
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
Add the following dependency to your app module's build.gradle file (project/app/build.gradle):
apply plugin: 'com.android.application'
android {
// ...
}
dependencies {
// ...
compile 'com.github.freshdesk:hotline-android:1.2.+'
}
Hotline SDK supports apps targeting Android version 5.0+. The SDK itself is compatible all the way down to Gingerbread (API Level 10).
"Missing/Bad FileProvider for Hotline. Camera capture will fail in devices running Nougat or later versions of OS (error code 354)"
To fix this, please include the provider in the AndroidManifest.xml as below and specify the authority in strings.xml. Assuming, com.example.demoapp is the package name of your app, the declaration would be
AndroidManifest.xml<provider android:name="android.support.v4.content.FileProvider" android:authorities="com.example.demoapp.provider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/hotline_file_provider_paths" /> </provider>
Strings.xml
<string name="hotline_file_provider_authority">com.example.demoapp.provider</string>
When the app's target is Android 8.0 or later, and by extension includes appcompat-v7 r26.0.0.+, you'll see the following errors
E/UncaughtException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/freshdesk/hotline/activity/InterstitialActivity;
package android.support.v7.app;
public class ActionBarActivity extends AppCompatActivity {
}
If your app targets 8.0, create a new Notification channel and pass the notification channel id to Hotline SDK as follows.
HotlineNotificationConfig notificationConfig = new HotlineNotificationConfig()
.setNotificationChannelId("custom_notif_channel");
Where `custom_notif_channel` is the channel id of the notification channel
2. Initializing Hotline
import com.freshdesk.hotline.*;
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstance) {
super.onCreate(savedInstance);
setContentView(R.layout.mainview);
HotlineConfig hlConfig=new HotlineConfig("YOUR-APP-ID","YOUR-APP-KEY");
Hotline.getInstance(getApplicationContext()).init(hlConfig);
}
}
2.1 Initialization Options
Enable or disable features like voice messaging (by specifying it in the config like below) before initialization.
HotlineConfig hConfig=new HotlineConfig("<YOUR-APP-ID>","<YOUR-APP-KEY>");
hConfig.setVoiceMessagingEnabled(true);
hConfig.setCameraCaptureEnabled(true);
hConfig.setPictureMessagingEnabled(true);
Hotline.getInstance(getApplicationContext()).init(hConfig);
3. User Information (Optional)
//Get the user object for the current installation
HotlineUser hlUser=Hotline.getInstance(getApplicationContext()).getUser();
hlUser.setName("John Doe");
hlUser.setEmail("john.doe.1982@mail.com");
hlUser.setExternalId("john.doe");
hlUser.setPhone("+91", "9790987495");
//Call updateUser so that the user information is synced with Hotline's servers
Hotline.getInstance(getApplicationContext()).updateUser(hlUser);
3.2 Updating User Properties (Meta Data)
You can capture and send additional metadata about the user and the events in the app, all of which also becomes a way to segment your users to later push messages to them.
/* Set any custom metadata to give agents more context, and for segmentation for marketing or pro-active messaging */
Map<String, String> userMeta = new HashMap<String, String>();
userMeta.put("userLoginType", "Facebook");
userMeta.put("city", "SpringField");
userMeta.put("age", "22");
userMeta.put("userType", "premium");
userMeta.put("numTransactions", "5");
userMeta.put("usedWishlistFeature", "yes");
//Call updateUserProperties to sync the user properties with Hotline's servers
Hotline.getInstance(getApplicationContext()).updateUserProperties(userMeta);
3.3 Clear User Data
Hotline.clearUserData(getApplicationContext())
4. Launching the Support Experience
Note : Only Message Channels with visibility set to "Visible to all users" will be displayed when using showConversations() API
// Launching Conversation List from click of a button in your app's screen
myConversationsButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Hotline.showConversations(getApplicationContext());
}
});
To filter and display only Message Channels tagged with a specific term, use the filterByTags API in ConversationOptions instance passed to showConversations() API as below.
Note : Message Channels with visibility set to "Visible in filtered view of conversations by tags" which are normally not visible when using showConversations() API, will also be displayed when tagged and the specific tag is passed to filterByTags API of ConversationOptions instance passed to showConversations() API
Eg: To link and display only specific Message Channels from say orders page in your app, those specific Message Channels can be tagged with the term "order_queries"
List<String> tags = new ArrayList<>();
tags.add("order_queries");
ConversationOptions convOptions = new ConversationOptions()
.filterByTags(tags, "Order Queries");
Hotline.showConversations(MainActivity.this, convOptions);
4.2. FAQ
// Launching FAQ from click of a button in your app's screen
myFAQButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Hotline.showFAQs(getApplicationContext());
}
});
4.2.1 FAQ Options
Customizations to the FAQ Flow can be achieved by specifying the relevant options in the FaqOptions instance passed to the showFAQs() API.
Eg.
// Launching FAQ from click of a button in your app's screen
myFAQButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
FaqOptions faqOptions = new FaqOptions()
.showFaqCategoriesAsGrid(true)
.showContactUsOnAppBar(true)
.showContactUsOnFaqScreens(false)
.showContactUsOnFaqNotHelpful(false);
Hotline.showFAQs(MainActivity.this, faqOptions);
}
});
To filter and display only FAQ Categories tagged with a specific term, use the filterByTags API with Filter Type as Category in FAQOptions instance passed to showFAQs() API as below.
Eg: To display FAQ Categories related to specific user type, those specific FAQ Categories can be tagged with the term "premium"
List<String> tags = new ArrayList<>();
tags.add("premium");
FaqOptions faqOptions = new FaqOptions()
.filterByTags(tags, "FAQs", FaqOptions.FilterType.CATEGORY);//tags, filtered screen title, type
Hotline.showFAQs(MainActivity.this, faqOptions);
4.2.3 Filter FAQs by tags
To filter and display only FAQs tagged with a specific term, use the filterByTags API with Filter Type as Article in FAQOptions instance passed to showFAQs() API as below.
Note : FAQs also inherit the tags from the parent FAQ Category.
Eg: To link to FAQs related to payment failure, those specific FAQs can be tagged with the term "payment_failure" and can be linked to from Payments page in the app
List<String> tags = new ArrayList<>();
tags.add("payment_failure");
FaqOptions faqOptions = new FaqOptions()
.filterByTags(tags, "payment_failure", FaqOptions.FilterType.ARTICLE);//tags, filtered screen title, type
Hotline.showFAQs(MainActivity.this, faqOptions);
4.2.4 Filter Message Channels displayed on clicking "Contact Us" in FAQs by tags
To filter and display only Message Channels tagged with a specific term when user clicks "Contact Us"in FAQ screens, use the filterContactUsByTags API in FAQOptions instance passed to showFAQs() API as below.
Eg: To display Message Channels related to specific section of FAQ show, those specific Message Channels can be tagged with the term "payment_failure"
List<String> tags = new ArrayList<>();
tags.add("payment_failure");
FaqOptions faqOptions = new FaqOptions()
.filterContactUsByTags(tags, "Payments"); //tags, filtered screen title
Hotline.showFAQs(MainActivity.this, faqOptions);
5. Displaying unread message count (Optional)
5.1 Unread message count across "All Conversations" :
If you would like to obtain the number of unread messages for the user, use the getUnreadCountAsync API
protected void onResume() {
Hotline.getInstance(getApplicationContext()).getUnreadCountAsync(new UnreadCountCallback() {
@Override
public void onResult(HotlineCallbackStatus hotlineCallbackStatus, int unreadCount) {
//Assuming "badgeTextView" is a text view to show the count on
badgeTextView.setText(Integer.toString(unreadCount));
}
});
}
5.2 Unread message count across "Conversations Filtered By Tags" :
If you would like to obtain the number of unread messages for the user across specific conversations filtered by tags, use the getUnreadCountAsync API
protected void onResume() {
List<String> tags = new ArrayList<>();
tags.add("premium"); //Tags to filter conversations by
Hotline.getInstance(getApplicationContext()).getUnreadCountAsync(new UnreadCountCallback() {
@Override
public void onResult(HotlineCallbackStatus hotlineCallbackStatus, int unreadCount) {
//Assuming "badgeTextView" is a text view to show the count on
badgeTextView.setText(Integer.toString(unreadCount));
}
}, tags);
}
6. Proguard Configuration (If Proguard is enabled in your app)
Holtine Android SDK from version 1.0.1 is configured out of the box to support proguard. Proguard will automatically pickup the config for the SDK, no manual configuration is necessary.
Some exceptions to the automatic configuration noted below:
- If target OS version is not Marshmallow (API Level 23), please include the following in the app's proguard-rules.pro
-dontwarn com.freshdesk.hotline.**
- If you are integrating Hotline SDK version 1.1.12 with proguard enabled and custom font support is not required, please include the following in the app's proguard-rules.pro
-dontwarn uk.co.chrishenx.calligraphy.**
This is no longer required as of version 1.0.13 onwards
7. Push Notifications
Prerequisites:
@Override
public void onTokenRefresh() {
String token = FirebaseInstanceId.getInstance().getToken();
Hotline.getInstance(this).updateGcmRegistrationToken(token);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (Hotline.isHotlineNotification(remoteMessage)) {
Hotline.getInstance(this).handleFcmMessage(remoteMessage);
} else {
//Handle notifications with data payload for your app
}
}
Option 2 : GCM
Please update the Hotline SDK with your GCM registration token once it becomes available.”
Hotline.getInstance(context).updateGcmRegistrationToken(token);
@Override
protected void onMessageReceived(String from, Bundle data) {
if(Hotline.isHotlineNotification(data)) {
Hotline.getInstance(this).handleGcmMessage(data);
return;
} else {
// Your application code goes here to handle other kinds of messages
}
}
7.2 Customizing Notifications
5. Activity to launch on up navigation from the messages screen launched from notification. The messages screen will have no activity to navigate up to in the backstack when its launched from notification. Specify the activity class name to be launched.
6. For specifying the accent color of the circle behind the small icon in notification
<color name="hotline_notification_accent_color">@color/red</color>
HotlineNotificationConfig notificationConfig = new HotlineNotificationConfig() .setNotificationSoundEnabled(true) .setSmallIcon(R.drawable.ic_notif_small_icon) .setLargeIcon(R.drawable.ic_notif_large_icon) .launchDeepLinkTargetOnNotificationClick(true) .launchActivityOnFinish(MainActivity.class.getName()) .setPriority(NotificationCompat.PRIORITY_HIGH); Hotline.getInstance(getApplicationContext()).setNotificationConfig(notificationConfig);
8. Send message on behalf of user
The app can send a message on behalf of the user using the sendMessage() API.
Note: This API would silently send a message and not launch the Hotline SDK UI
Eg: To send a message on a channel tagged "premium", the API can be invoked as below
String tag = "premium"; String msgText = "User has trouble with order #1234"; HotlineMessage hotlineMessage = new HotlineMessage().setTag(tag).setMessage(msgText); Hotline.sendMessage(getContext(), hotlineMessage);
9. PERMISSIONS
- android.permission.RECORD_AUDIO
- android.permission.WRITE_EXTERNAL_STORAGE
If the app doesn’t require the voice messaging features, the permissions can be removed by specifying the permission along with tools:node="remove" in your app’s manifest
<uses-permission android:name="android.permission.RECORD_AUDIO" tools:node="remove" />
9. Checklist for launch
- Ensure you are initializing the SDK in the onCreate of the main / launcher activity
- Check that you have push notifications working right from your first launch, and have the right notification icons configured
- Ensure the App name is set right for your notifications
- Negate the audio recording permissions in your manifest if you are not using voice messaging
- See our Theming and Customization document here to make sure you are matching the experience with the rest of your app
- Configure your default channel name and welcome message right even if you aren't using other channels
- Capture the unique user identifier, email, phone number, or any other unique customer identifiers with the SDK to ensure smooth use of APIs, as well as for best use of our "Smart Plugs" feature on the dashboard.
- Ensure the push notifications are working for new installs as well as upgrades from your previous versions.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article