Skip to content

Working with http/https schemes in StreetHawk Growth (Android)

Introduction

The article describes steps to use StreetHawk growth with http and https as deeplink scheme inside your Android application. The idea is to bundle the deeplink url with http or https scheme inside a application specific deeplink url

Implementation Steps

  • Register application specific scheme in AndroidManifest.xml

Register your application specific scheme in AndroidManifest.xml (preferably in Launcher Activity of application) as shown below.

<intent-filter android:label="secondPage">
    <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="MyFirstApp" />    <!--  Replace with your application specific scheme -->
</intent-filter>

Make sure to include the application scheme inside it's own intent-filter tabs and not to merge with existing ones as doing so wont register your application specific scheme.

  • Append the application specific scheme before the actual deeplink URL

Call originate share when user press the share button. Simply append your application specific scheme to your original deeplink url as shown below. Share the url received from StreetHawk.

    Button share = new Button(this);
        share.setText("Share");
        share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

        /*Replace with your application specific scheme*/   
        String appScheme = "MyFirstApp://";    

                String ID = "ShareViaFacebook"

        /*Append appScheme before https scheme*/
                String shareLink = appScheme+"https://homepage?recipe=chocolatechipcookie";

                String utm_source = "Facebook";
                String utm_medium = "cpc";
                String utm_term = "facebookAdd";
                String campaign_content = "best chocolate chip cookie recipe";
                String default_ur = "http://recipeApp.com/chocolatechipcookie";

                Growth.getInstance(this).originateShareWithCampaign(ID, shareLink, utm_source, utm_medium,utm_term, campaign_content, default_ur, new IGrowth() {
                            @Override
                            public void onReceiveShareUrl(String shareUrl) {
                     Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("text/plain");
                    intent.putExtra(Intent.EXTRA_TEXT,shareUrl);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    mContext.startActivity(intent);       // Launch default application picker
                            }

                            @Override
                            public void onReceiveErrorForShareUrl(JSONObject errorResponse) {

                            }
                        });
            }
        });
}
  • Extract the deeplink with http/https scheme and launch with deeplink url

Implement handleHttpDeepLink function inside your application and call the same from the onCreate function of the activity registered with your deeplink url (preferably launcher activity of your application)

 private void handleHttpDeeplink(){
        String SH_SCHEME = "MyFirstApp://";
        Intent intent = getIntent();
        String scheme=intent.getScheme();
        if(scheme.equals(SH_SCHEME)){
            String httpUrl = intent.getDataString().replace(SH_SCHEME,"");
            try {
                int index = httpUrl.indexOf(':');
                if (index > 0) {
                    scheme = httpUrl.substring(0, index);
                    if(scheme.equals("http") || scheme.equals("https")){
                        Intent deepLinkIntent = new Intent();
                        deepLinkIntent.setAction("android.intent.action.VIEW");
                        deepLinkIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        deepLinkIntent.setData(Uri.parse(httpUrl));
                        startActivity(deepLinkIntent);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }
        }
    }

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    ...
    ...
     handleHttpDeeplink();  //Calling handleHttpDeeplink function
    }