Generate Client ID & Client Secret to authenticate your application with PepperTalk. Follow these steps to generate Client ID & Client Secret:
- Go to PepperTalk Console
- Fill in the details and signup
- Validate your email address by clicking on the link you get in your email inbox
- Create a new application by selecting the "New Application" option from the menu on left hand side
- Enter the Application Description
- Optionally, select and enter push notification related information to support remote OS notifications
- Find Client ID & Client Secret in the 'Clients' tab on your application page
Update your client_id and client_secret in [strings.xml] 3
<string name="client_id">CLIENT_ID</string>
<string name="client_secret">CLIENT_SECRET</string>
Add PepperTalk to your application
Gradle dependency
compile 'com.espreccino:peppertalk:0.4.15'
[build.gradle] 2
Add ContentProvider to AndroidManifest.xml (Unique authority)
${applicationId} will automatically load your application package name from build.gradle. For different flavours add a suffix.
<provider
android:name="com.espreccino.peppertalk.io.TalkProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:enabled="true"
android:label="PepperTalk"
android:syncable="true"
tools:replace="android:authorities"/>
Initialize PepperTalk
PepperTalk.getInstance(context)
.init(clientId,
clientSecret,
userId)
.connect();
InApp Notifications
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
PepperTalk.NotificationBuilder builder = new PepperTalk.NotificationBuilder();
builder.notificationStatIcon(R.drawable.ic_stat_notification);
builder.soundUri(soundUri);
builder.taskStackBuilder(TaskStackBuilder.create(getApplicationContext())
.addNextIntentWithParentStack(intent));
PepperTalk.getInstance(this).enabledInAppNotifications(builder);
Start Conversation
PepperTalk.getInstance(context)
.chatWithParticipant(userId)
.topicId(topicId)
.topicTitle("Let ride!")
.start();
Message Listener
- New Message
- Unread count
PepperTalk.getInstance(context)
.registerMessageListener(new PepperTalk.MessageListener() {
@Override
public void onNewMessage(String userId, String topicId, int unreadCount) {
//Update unread count in UI
}
});
// Use Google Play and Client services to get Registration ID.
PepperTalk.getInstance(context).registerGcm(regId);
Check is notification Intent is from PepperTalk [Code] 6
PepperTalk.getInstance(context).isNotificationFromPepperTalk(intent);
Handle PepperTalk GCM notification [Code] 7
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
PepperTalk.NotificationBuilder builder = new PepperTalk.NotificationBuilder();
builder.notificationStatIcon(R.drawable.ic_stat_notification);
builder.soundUri(soundUri);
Intent intent1 = new Intent(getApplicationContext(), MainActivity.class);
builder.taskStackBuilder(TaskStackBuilder.create(getApplicationContext())
.addNextIntentWithParentStack(intent1));
PepperTalk.getInstance(this).handleNotification(intent, builder);
[Adding GCM service to manifest] 8
Add the following to your pom.xml [(more info using m2eclipse)] 4
<dependency>
<groupId>com.espreccino</groupId>
<artifactId>peppertalk</artifactId>
<version>0.4.15</version>
</dependency>
Download the latest aar [here] 5
Detailed instructions on setting up Eclipse with ADT is here