See Hipmob in action on iOS with Wanderplayer and Android with Wanderplayer
Hipmob For Android
Overview
15-minute integration
- Register for an account at https://manage.hipmob.com/ (if you haven't already done so). Once you register a Hipmob application entry will be created for you and an application ID will be generated. Remember this application ID: you'll use it later.
- Download the Hipmob Android library JAR file. This includes all the dependencies required.
- Copy the Hipmob library JAR file into your project's library folder (libs, if you're using the default project folder structure in Eclipse).
- Add the Hipmob library JAR file into your project's build path.
- Add the INTERNET, WRITE_EXTERNAL_STORAGE and RECORD_AUDIO permissions to the AndroidManifest.xml file. This will allow sending/receiving of text, picture and audio messages.
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.RECORD_AUDIO" />
- Add the HipmobCore activity definition to the AndroidManifest.xml file.
<activity android:name="com.hipmob.android.HipmobCore" />
- Use an Intent to call the HipmobCore activity. You'll need the application ID from step 1: pass that as HIPMOB_KEY.
// create an intent Intent i = new Intent(this, com.hipmob.android.HipmobCore.class); // REQUIRED: set the appid to the key you're provided i.putExtra(HipmobCore.KEY_APPID, HIPMOB_KEY); // REQUIRED: pass the host user identifier. i.putExtra(HipmobCore.KEY_USERID, "my-user-identifier-that-is-unique"); // launch the chat window startActivity(i);
Connect it to a button (you can see an example in the WanderPlayer app in the Google Play Store). - And we're complete. Build your app.
- To log into Adium.
- To log into iChat.
- To log into Instantbird.
- To log into imo.
- To log into Pidgin.
- [PENDING] To log into Empathy.
- [PENDING] To log into Xabber.
- [PENDING] To log into Monal.
- If your XMPP client is not listed above, you can login using the username and password with a domain set to hipmob.com.
Requirements
- Hipmob integration requires familiarity with Android development: this guide assumes you are using Eclipse with the ADT plugin (but will still work if you are using Ant or Maven: we work with everyone). For simplicity it is not an Android library: it is only a JAR file you have to include in your project.
- We currently support Android development using some rapid development environments such as Titanium and Parse. We dont yet support web-based development platforms (such as Trigger.io) or alternate languages (such as C# as used by MonoDevelop): we may provide such support in the future.
- We currently require that your app be developed for devices running Android 2.0 or higher (we don't think that's unreasonable: Android 1.6 was released in September of 2009, so its been a little while).
- Your app will need (at a minimum) INTERNET privileges (hard to chat if you aren't connected to the Internet) and you'll have to add our activity definition to your AndroidManifest.xml file.
- As an administrator, you have to have an XMPP compatible client to connect to our communication network (there are a ton of free ones: on Windows we recommend Pidgin, on OSX Adium, on Linux Empathy, on Android Xabber, and on iOS Monal. If you don't see your platform here we still love you: just reach out to us if you can't find one and we'll work with you to find one that works). Any other standards-compliant XMPP client should just work. We're also working on integration with federated XMPP servers (such as Google Talk and Facebook), and once that is ready you'll be able to use your existing messaging accounts.
Details
Library Options
- In your Android project, create a directory named libs at the root of your project (next to src/, res/, etc.).
- Copy the Hipmob Android JAR file to the libs/ directory.
- In Eclipse, right-click (on Windows/Linux; on OSX it should be a a Ctrl+click, or a 2-finger click on the track pad) the Hipmob Android JAR file in the Package Explorer, select Build Path > Add to Build Path.
Manifest Settings
<uses-permission android:name="android.permission.INTERNET" />To support picture and audio messaging, you'll also need to add the WRITE_EXTERNAL_STORAGE and RECORD_AUDIO permissions. Hipmob for Android uses progressive enhancement: if you only provide the INTERNET permission then only text messaging will be available, if you only provide the INTERNET and WRITE_EXTERNAL_STORAGE permissions then only text and picture messaging will be available, and if you provide INTERNET, WRITE_EXTERNAL_STORAGE and RECORD_AUDIO permissions then text, picture and audio messaging will be available.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.RECORD_AUDIO" />You'll also need to register the Hipmob Activity to be launched as part of your app: the Activity class is com.hipmob.android.HipmobCore and can be added to your AndroidManifest.xml file very easily:
<activity android:name="com.hipmob.android.HipmobCore" />And that's it. As a complete example, this is the AndroidManifest.xml file from the test project Download the Hipmob Android Testing Project Source Code: it shows the permissions as well as the Activity registration (WRITE_EXTERNAL_STORAGE and RECORD_AUDIO are optional).
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hipmob.android.testing" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="5" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".HipmobTestActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.hipmob.android.HipmobCore" android:label="Hipmob" /> </application> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> </manifest>
Chat Sessions
// create an intent Intent i = new Intent(this, com.hipmob.android.HipmobCore.class); // REQUIRED: set the appid to the key you're provided i.putExtra(HipmobCore.KEY_APPID, HIPMOB_KEY); // REQUIRED: pass the host user identifier. i.putExtra(HipmobCore.KEY_USERID, "my-user-identifier-that-is-unique"); // launch the chat window startActivity(i);
Figure 1: Connecting to the Hipmob communication network
Figure 2: Admins are available
Figure 3: No admins are available
User Interaction
Figure 4: Messages on the Android device
Figure 5: Conversation in the admin's XMPP client
Figure 6: send a picture or voice message
User Information
Customization: Activity Title
Customization: Notices
Localization
Available Messages
checkPendingMessages method on the HipmobRemoteConnection class. You pass this a Context (such as the Activity or Service that is performing the check) and a HipmobPendingMessagesListener to receive the results.
HipmobRemoteConnection.checkPendingMessages(this, HIPMOB_KEY,
new HipmobPendingMessageListener(){
@Override
public void pendingMessageCount(int count) {
// <count> is the number of pending messages. If no messages are available it will be 0.
// TODO: notify the user somehow that messages are waiting.
}
@Override
public void pendingMessageLookupFailed() {
// TODO: ignore, or notify the user that an error occured performing the lookup.
}
});
Push Notifications
Configuration Options
Application ID
// create an intent
Intent i = new Intent(this, com.hipmob.android.HipmobCore.class);
// REQUIRED: set the appid to the key you're provided
i.putExtra(HipmobCore.KEY_APPID, "fefed30c17f0409f89d5a4953c0fce1f");
// launch the chat window
startActivity(i);
We recommend the use of a class final static variable to minimize the possibility that the application ID is incorrectly defined anywhere. As an example, if you have an Activity called MyMainActivity, in that Activity you could define your key like this:
public static final String HIPMOB_KEY = "fefed30c17f0409f89d5a4953c0fce1f";You can then use this value everywhere you want to be able to open a chat window:
i.putExtra(HipmobCore.KEY_APPID, MyMainActivity.HIPMOB_KEY);This will be the style we will use going forward.
User ID
// create an intent
Intent i = new Intent(this, com.hipmob.android.HipmobCore.class);
// REQUIRED: set the appid to the key you're provided
i.putExtra(HipmobCore.KEY_APPID, "fefed30c17f0409f89d5a4953c0fce1f");
// set the user identifier
i.putextra(HipmobCore.KEY_USERID, "my-magical-user-identifier");
// launch the chat window
startActivity(i);
Note Because Hipmob does not parse the provided user identifier or look at it in any other way, the Hipmob communication network will accept the same user identifier for multiple devices. Note that future functionality may depend on uniqueness of the user identifier.
Name
// create an intent
Intent i = new Intent(this, com.hipmob.android.HipmobCore.class);
// REQUIRED: set the appid to the key you're provided
i.putExtra(HipmobCore.KEY_APPID, "fefed30c17f0409f89d5a4953c0fce1f");
// set the user's name
i.putextra(HipmobCore.KEY_NAME, "Jack Hawksmoor");
// launch the chat window
startActivity(i);
// create an intent
Intent i = new Intent(this, com.hipmob.android.HipmobCore.class);
// REQUIRED: set the appid to the key you're provided
i.putExtra(HipmobCore.KEY_APPID, "fefed30c17f0409f89d5a4953c0fce1f");
// set the user's email
i.putextra(HipmobCore.KEY_EMAIL, "jack@theauthority.com");
// launch the chat window
startActivity(i);
Location
Note If this value is obtained from the GPS location functionality on the device, be certain to inform the user and obtain the necessary consent to transmit their location information.
// create an intent
Intent i = new Intent(this, com.hipmob.android.HipmobCore.class);
// REQUIRED: set the appid to the key you're provided
i.putExtra(HipmobCore.KEY_APPID, "fefed30c17f0409f89d5a4953c0fce1f");
// set the user's location string
i.putextra(HipmobCore.KEY_LOCATION, "Tokyo, Japan");
// launch the chat window
startActivity(i);
Latitude/Longitude
Note If this value is obtained from the GPS location functionality on the device, be certain to inform the user and obtain the necessary consent to transmit their location information.
// create an intent
Intent i = new Intent(this, com.hipmob.android.HipmobCore.class);
// REQUIRED: set the appid to the key you're provided
i.putExtra(HipmobCore.KEY_APPID, "fefed30c17f0409f89d5a4953c0fce1f");
// set the user's geolocation
i.putExtra(HipmobCore.KEY_LATITUDE, 37.423105);
i.putExtra(HipmobCore.KEY_LONGITUDE, -122.082399);
// launch the chat window
startActivity(i);
Note The latitude and longitude values provided must be in decimal degrees.
Context
// create an intent Intent i = new Intent(this, com.hipmob.android.HipmobCore.class); // REQUIRED: set the appid to the key you're provided i.putExtra(HipmobCore.KEY_APPID, "fefed30c17f0409f89d5a4953c0fce1f"); // set the user's context information i.putextra(HipmobCore.KEY_CONTEXT, "On the Carrier"); // launch the chat window startActivity(i);
Present/Away Notices
// create an intent Intent i = new Intent(this, com.hipmob.android.HipmobCore.class); // REQUIRED: set the appid to the key you're provided i.putExtra(HipmobCore.KEY_APPID, "fefed30c17f0409f89d5a4953c0fce1f"); // set the present and away notices i.putExtra(HipmobCore.KEY_AWAY_NOTICE, "Nobody home: drop us a line, we'll get back to you."); i.putExtra(HipmobCore.KEY_PRESENT_NOTICE, "We're right here: what can we help you with?"); // launch the chat window startActivity(i);
TItle
// create an intent Intent i = new Intent(this, com.hipmob.android.HipmobCore.class); // REQUIRED: set the appid to the key you're provided i.putExtra(HipmobCore.KEY_APPID, "fefed30c17f0409f89d5a4953c0fce1f"); // set the title of the chat window i.putExtra(HipmobCore.KEY_TITLE, "Chat with the Engineer"); // launch the chat window startActivity(i);
