Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Finishing the Link

Kevin Perez
PLUS
Kevin Perez
Courses Plus Student 8,180 Points

Browser doesn't open the app

Android manifest

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.teamtreehouse.deeplinks">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>

            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data
                android:scheme="https"
                android:host="teamtreehouse.com"
                android:pathPrefix="/tracks"/>
        </intent-filter>
    </activity>
</application>

</manifest>

MainActivity

private TextView mTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTextView = (TextView) findViewById(R.id.textView); Intent intent = getIntent(); if(intent.getAction().equals(Intent.ACTION_VIEW)){ String dataString = intent.getDataString(); Toast.makeText(this, dataString, Toast.LENGTH_SHORT).show(); mTextView.setText(formatDataString(dataString)); } }

private String formatDataString(String dataString) {
    int indexOfSlash = dataString.lastIndexOf("/");
    String urlEnd = dataString.substring(indexOfSlash + 1);
    String[] words = urlEnd.split("-");
    String finalString = "";
    for (String word : words) {
        word = capitalizeWord(word);
        finalString += word + " ";
    }
    return finalString.substring(0, finalString.length() - 1);
}

private String capitalizeWord(String word) {
    return Character.toUpperCase(word.charAt(0)) + word.substring(1);
}
Varun Singh
Varun Singh
Courses Plus Student 971 Points

Hi kevin, The code is correct and also you dont need to add " new app indexing " as well, It does open the track page inside your app but for that you need to open your phone settings -go to app section or app info- select open by default -open supported links in the app-always ask . Also, you can directly open inside your app by selecting-open in app :)