Skip to content

Supporting Application Specific Dialogs (Android)

StreetHawk SDK supports displaying of StreetHawk push messages in dialogs customised for your application by delivering push data to application using ISHObserver. Below are the steps for handling application specific dialogs.

Step 1. Implement ISHObserver

Implement ISHObserver interface in your application.

   public class CustomDialogService extends Service implements ISHObserver{

.............
..............

    @Override
    public void onReceivePushData(final PushDataForApplication pushData) {

     }
    @Override
    public void onReceiveResult(PushDataForApplication resultData,int result) {

    }
    @Override
    public void shReceivedRawJSON(final String title,final String message,final String json){

    }
    @Override
    public void shNotifyAppPage(String pageName) {
        // Ignore this for non native platforms

    }


}

Step 2. Implement Custom dialog in onReceivePushData()

onReceivePushData() will receive push data from StreetHawk server bundled inside an object of type PushDataForApplication.

 @Override
    public void onReceivePushData(final PushDataForApplication pushData) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                final Dialog customDialog = new Dialog(context);
                customDialog.setContentView(R.layout.sample_custom_dialog_from_app);
                customDialog.setTitle(pushData.getTitle());
                Button button = (Button) customDialog.findViewById(R.id.custom_okay);
                button.setOnClickListener(pushData.getPositiveButtonOnClickListener(customDialog, getApplicationContext()));
                Button button2 = (Button) customDialog.findViewById(R.id.custom_dismiss);
                button2.setOnClickListener(pushData.getNegativeButtonOnClickListener(customDialog, getApplicationContext()));

                customDialog.show();
            }
        });
    }

Step 3. Handle OnClickListeners.

Call StreetHawk's onClickListeners to handle push results and analytics.StreetHawk SDK exposes 3 Onclick listeners

  • pushData.getPositiveButtonOnClickListener : For positive button clicks
  • pushData.getNegativeButtonOnClickListener : For negative button clicks
  • pushData.getNeutalButtonOnClickListener : For neutral button clicks.

Below is sample code for handling Positive and Negative button clicks of your custom dialog.

Button button = (Button) customDialog.findViewById(R.id.custom_okay);
button.setOnClickListener(pushData.getPositiveButtonOnClickListener(customDialog, getApplicationContext()));
Button button2 = (Button) customDialog.findViewById(R.id.custom_dismiss);
button2.setOnClickListener(pushData.getNegativeButtonOnClickListener(customDialog, getApplicationContext()));

Step 4. Register ISHObserver

Register object of the class implementing ISHObserver with StreetHawk using registerSHObserver API. The API should be called before StreetHawk.init()

Push.getInstance(getApplicationContext).registerSHObserver(CustomDialogServiceObject); 

Step 5. Disable default dialogs

Similarly, notify StreetHawk SDK about your application using custom dialogs by calling setUseCustomDialog with true as the function argument. Failure to do so will make StreetHawk SDK to generate default dialogs.

Push.getInstance(getApplicationContext).setUseCustomDialog(true);