How to open Tumblr links in their app

3 years, 2 months ago

(12 comments)

Do you have Tumblr's Android app? Are you annoyed that links to Tumblr posts nevertheless open in a browser, whereupon they nag you to use their app?

UPDATE: Some time in March(?) 2016, the Tumblr app itself started offering to handle URLs of Tumblr posts. Unfortunately it seems to only open the relevant blog showing most recent posts, not the post that was linked to. The same problem now manifests when I open a post via my redirector. So the redirector is no longer helpful and I do not recommend using it.

Original post below for posterity / developer interest.


Short answer: install this until they fix it (I have asked them to). Longer answer: here's how to solve the next similar problem yourself with Android Studio and some basic knowledge of Intents and intent-filters.

Aside: I actually wrote the fix in AIDE (£7.75 for non-trivial features) using only my phone, and just tidied it up in Studio.

So, the problem we have is that when you click on a link like http://kaberett.tumblr.com/post/126329233520/title, depending on your settings, you'll either go directly to a browser or you'll get an "Open with" choice in which the Tumblr app is not listed. The reason is simply that the Tumblr app hasn't declared itself capable of opening such URLs in its AndroidManifest.xml. But when you open a post in a mobile browser and look at the top of the page, there's a big "Open in app" button. So how does that button work? It links to a different URI which the app does handle:

tumblr://x-callback-url/blog?blogName=kaberett&page=permalink&postID=126329233520#_=_

The fix, then, is to make the world's simplest app, that does what Tumblr should have done and declares itself capable of opening the ordinary http:// URL, and when it gets one it'll just launch the tumblr:// URL and exit. To do this, create a new Android project in your preferred tool, starting with a blank Activity if given the choice, then set up AndroidManifest.xml: remove the original intent-filter with action MAIN and category LAUNCHER, which provides an icon in the app drawer, which we don't want. Instead, add this one:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="http" android:host="*.tumblr.com" android:pathPattern="/post/.*" />
    <data android:scheme="https" android:host="*.tumblr.com" android:pathPattern="/post/.*" />
</intent-filter>

This just says the Activity is a way to open URLs with the given host and path and it's safe to use from the browser. Note that this doesn't handle links to a whole blog, which you could do by dropping the path pattern, but then you'd catch everything on www.tumblr.com as well and you'd have to work out whether some of those should still open in a browser.

You should also set android:theme="@android:style/Theme.NoDisplay" and android:stateNotNeeded="true" on the activity for a quick and seamless visual transition to Tumblr without displaying any UI of our own. Then in the activity's Java source (abridged below):

final Uri uri = getIntent().getData();
final String user = uri.getHost().substring(0, uri.getHost().indexOf('.'));
final String postId = uri.getPathSegments().get(1);
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(
    String.format(getString(R.string.tumblr_app_uri), user, postId)));
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
finish();

This extracts the username and post ID from the URL, fills in the new URI string, launches that and exits. Try it out! The first time around you'll need to choose the app and click "Always"; on subsequent occasions clicking a link to a post should Just Work.

As you'll soon discover if you look through Google Play's terms, publishing something like this is a thorny issue, likely to result in an argument with them about whether you're impersonating Tumblr and what your content rating should be. It seemed safer to just publish an APK, which people can install almost as easily, though it does require ticking a box to acknowledge that you're installing something Google hasn't vetted. In any case, hopefully Tumblr will fix this properly soon.

Comments

Hernytan 3 years, 1 month ago

Extremely helpful! Installed it and it works perfectly

Link | Reply

Ason 2 years, 11 months ago

Thanks, works perfect on my LG G2,
Sorry to say that there is problem with my wifes Nexus 6 android 6.0.1 and tumblr 5.0.0.13.

Link | Reply

John 2 years, 9 months ago

Thanks! This was immensely helpful and solved the problem!

Link | Reply

Joshua 2 years, 9 months ago

How exactly do I do this?

Link | Reply

Chris Boyle 2 years, 9 months ago

Install the APK file from https://github.com/chrisboyle/tumblrredirector/releases - you will first have to change a setting on your Android device to allow installation of software from places other than Google Play, if you haven't already. Its name may vary; on mine it appears at Settings / Security / Unknown sources.

Obligatory health warning: you should only install APKs from places you trust, as a malicious APK can harm your device, steal your personal information, etc. Any random APK you find on the web has not been vetted or scanned by Google (and might not be scanned during or after installation, depending on your device/software).

Link | Reply

Joshua 2 years, 9 months ago

I've done that, and it still opens in the browser.

Link | Reply

Chris Boyle 2 years, 9 months ago

Please check that the URL looks like http://kaberett.tumblr.com/post/126329233520/title i.e. the link is to an individual post not a whole blog, and this blog does not use a custom domain (or just tell me the link?)

Please also check that the list of apps at Settings / Apps includes an entry for Tumblr Redirector, and if you click on it and there's an "Open by default" item to click on, let me know what's on the screen beyond that.

Link | Reply

Eric 2 years, 8 months ago

So this does seem to work for individual blog posts, but not for the whole blog (which is what you seem to indicate above). Is there no way make that functionality work?

Link | Reply

Chris Boyle 2 years, 8 months ago

As I said above you would end up catching www.tumblr.com and you would have to bounce some or all of the URLs under that hostname to a browser. Doing that without just relaunching the redirector could be tricky, and this was only a 20-minute hack.

Regardless, Tumblr have since broken things in their own inimitable style, see the new bold 2nd paragraph above, and the redirector is no longer useful.

Link | Reply

Eric 2 years, 8 months ago

Well, you tried. Thanks, Chris.

Link | Reply

Domi 1 year, 11 months ago

Is there a fix for apple? Im using an ipad and cant use that download link

Link | Reply

Chris Boyle 1 year, 11 months ago

Sorry, I know nothing about Tumblr on iOS as I have no Apple products. (As noted at the top of the post, this Android redirector is defunct anyway.)

Link | Reply

New Comment

required

required (not published)

optional