Skip to content

In-App Message / Feeds

Introduction

Feed module is used for sending In-App messages to your application. The module is handy if you wish to

  • Store locally push message received by application for future reference by application users
  • Send message to users who have denied receiving push messages
  • Feed items.

Integration Steps

Integration of StreetHawk's Analytics module is the prerequisite for this module. Click here for the documentation on StreetHawk Analytics module.

  • Adding dependencies

For Android Studio as your IDE, add the following code in application's build.gradle under dependencies.

dependencies {
...
   compile 'com.streethawk:feeds:1.8.22'
}
  • Implement ISHFeedItemObserver

Implement ISHFeedItemObserver in the activity you wish to present the feed item

import com.streethawk.library.feeds.ISHFeedItemObserver;
import com.streethawk.library.feeds.SHFeedItem;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Feeds extends AppCompatActivity implements ISHFeedItemObserver {
...

@Override
    public void shFeedReceived(final JSONArray feeds) {

//TODO: Parse and display feed items here

    }
}
  • Request feed item from server

Call feed module's readFeedData API to request feeds from the server.

 @Override
    public void onResume() {
        super.onResume();
int offset = 0;
        SHFeedItem.getInstance(this).readFeedData(offset);
    }

    /**
     * Read feed data after the given offset number
     * @param offset
     */
    private void fetchFeedData(int offset){
        SHFeedItem.getInstance(this).readFeedData(offset);
    } 
  • Notify user when new feed is available (Optional)

You can further notify users when a new feed item is available (sing badges or local notifications) by implementing BroadCastReceiver to read action com.streethawk.intent.action.newfeed as shown below.

  • Add Broadcast receiver in AndroidManifest.xml
<receiver
      android:name=".FeedBroadCastReceiver"
      android:enabled="true"
      android:exported="true">
     <intent-filter>
           <action android:name="com.streethawk.intent.action.newfeed" />
   </intent-filter>
</receiver>
  • Add custom code in onReceive function
public class FeedBroadCastReceiver extends BroadcastReceiver {
    public FeedBroadCastReceiver() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        //TODO: Add code to display local notification or badge 

    }
} 
  • Sending Feed Acks

Send the feedack to acknowledge receipt of an individual feed item

SHFeedItem.getInstance(this).sendFeedAck(feedId);

where feedId is the identifier for the feed item received from StreetHawk server

  • Sending FeedResults

Send Feed results to report actions taken by the user on a feed item. Feed result can be one the three values as listed below

Title Feed Result Description
Accepted 1 Denotes a positive action on Feed item. For example Rate
Later 0 Denotes a neutral action on Feed item. For example Later.
Declined -1 Denotes a negative action on Feed item. For example Cancel
SHFeedItem.getInstance(this).notifyFeedResult(feedid,result);

where feedId is the identifier for the feed item received from StreetHawk server and result is one of the values listed in above table.