Deep Linking

Introduction

Deep Linking refers to the process of creating a link that appears on the web and which, when opened from a device, takes the user directly into your app and directly to the content referred to in the link.

Socialize provides a simple way to enable deep linking for your app(s) which means that any and all links to content shared via Socialize will be pre-configured to “deep link” into the content of your app.

Note

Deep Linking requires an Entity Loader. Refer to Entity Loaders for more details.

Enabling Deep Linking

Enabling Deep Linking is a simple 3 step process:

Step 1 - Setup a Custom Url Scheme at getsocialize.com

From your Dashboard at getsocialize.com go to the SmartDownloads section

images/custom_url0.png

Scroll to the bottom of the page to the section entitled, Open App URL Schema Settings

images/custom_url1.png

Enter a custom URL scheme. This can be anything however for the purposes of this example we have used “socialize” as the scheme:

socialize://?key={{entity_key}}

The {{entity_key}} portion is a place-holder into which we (Socialize) will automatically insert the entity key.

Step 2 - Create an Activity to handle custom URLs

You can either create a new Activity to handle deep linking (recommended) or simply add the code below to an existing activity.

//Create a new activity, or use an existing activity in your app
public class MyAppActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		
		// Get the URI of the link
		Uri uri = getIntent().getData();
		
		if(uri != null) {
			// We have a uri
			String key = uri.getQueryParameter("key");
			
			if(key != null) {
				// Use EntityUtils to display the entity within the app (requires an Entity Loader)
				EntityUtils.showEntity(this, key, new EntityGetListener() {
					@Override
					public void onGet(Entity result) {
						// Do nothing
					}
					
					@Override
					public void onError(SocializeException error) {
						// Handle error
					}
				});
			}
			else {
				// Handle no key
			}
		}
		else {
			// Handle no uri
		}
	}
}

Step 3 - Configure your app to handle custom URLs

Finally configure the activity in your AndroidManifest.xml to handle URLs with this scheme

<activity android:name=".MyAppActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="socialize"/>
    </intent-filter>             
</activity>