Android Browser Facebook Redirects Not Always Failing for URL

I am truly pickled and desperate for help with the critical problem I am experiencing.

I spent several months building an HTML5 app / website along with a native Android app, which is just a WebView wrapper for an HTML5 website. One of the main features of the application is that users can share application URLs with Facebook and Twitter, etc., so that their friends can follow common URLs that open either the HTML5 version of my application in a browser, or IMPORTANT if they are on Android and they have my own Android application installed, they will SKIP TO OPEN IN MY APPLICATION.

This is a rather long complicated problem, so for simplicity I will use some specific terms sequentially in this post:

  • "MyApp user" is an Android device user who has my own Android application installed.
  • "non-MyApp user", an Android device user who does not have my Android application installed.
  • "stock browser user", an Android user using the stock browser.
  • "non-stock browser user", an Android user who uses a non-stock browser (note that the Galaxy SII app for Samsung Galaxy SII is considered not stocked).
  • "select the application dialog" in the Android OS dialog box that appears asking the user which application they want to open the action / intent / url / document, and if they want to use this application by default always

My AndroidManifest.xml contains the following ...

<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="http" android:host="myapp.com" android:pathPrefix="/" />
</intent-filter>

When testing this WORKS PERFECTLY in any normal scenario. For example, if the “MyApp user” follows a direct link to http://myapp.com/sharedpage , the “select application” dialog box appears. Great, I definitely configured my AndroidManifest.xml correctly.

Facebook. , Facebook, Android- Facebook, - Facebook (http://m.facebook.com) URL-, Facebook. , http://myapp.com/sharedpage , Facebook URL-:

http://m.facebook.com/l.php?u=http%3A%2F%2Fmyapp.com%2Fsharedpage&h=EAQGpLtuF&enc=AZMXYZg7XwQ39zlWkKSGnLw62lEbtbMeWFmRwRZINoOcg0UgZe3fUVPgqQzV1nuTipSVnquV3a3ovqu7HQFUf3bb3ZJ1gYG8dEOJXzPf6RJGflf9_x8w-6CCXu8G2VZqgfD7lx6EbLTSKLnF56_o5khHybycPUlhpdfLsk6M9muer4jMOmPK6_kfjTq2gvnYNNpStcF0ilJD6nacPqx_1xsdYkUMpKYWbJfSo7qqv1S5xT5KRaLPxl8zmAkYc0FhwyTdn-tUGwRBbbdM4QCd2Z75Tb_VeJG3LvbDwFAbp6G3kH3LOSxVtTd5MST4pUW8xmhNeTUVBVXV16OD27QcsSWOlEfL72fxn11PDE5s4WWsXMnwhDJLUAWOAna7lziBnWzjZdlQK_amI9nhcegaOLDLNFCp125rZS3jxFXf7gtF9g0BsmnPZ2Gjxkc6UgQXhEYldllq9nwpShGbnZDlSg0_&s=1

" MyApp" Facebook, ...

MyApp Stock Browser:

Android Android Android-, FINE, ...

MyApp Non-Stock Browser:

, ...

  • Android-, . Dolphin HD/mini, Opera Mobile/Mini ..,
  • Android (, Samsung Galaxy SII ..) , ,

... , ...


, , HTML- "clientSideRedirector.htm"

<html><body><script>
   window.location.href = "http://myapp.com/sharedpage";
</script></body></html>

My-App/non-stock http://myapp.com/clientSideRedirector.htm, " " . .

My-App/stock http://myapp.com/clientSideRedirector.htm, .

, , share/redirect Facebook.

(302)

, , .NET dotNetRedirect.ashx:

public class ShareRedirect : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
            context.Response.Redirect("http://myapp.com/sharedpage");
    }
    public bool IsReusable { get { return false; } }
} 

.
My-App http://myapp.com/dotNetRedirect.htm " " . , !


A

(Double redirect: Facebook l.php URL )

, Facebook. http://myapp.com/dotNetRedirect.ashx URL- Facebook, , , Facebook dotNetRedirect.htm, " " .

, , , , , / " ", . .


B

( )

, , , URI, " ".

AndroidManifest.xml:

<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="myapp" />
</intent-filter>

redirect.htm

<html><body><script>
   window.location.href = "myapp.com://sharedpage";
</script></body></html>

. " " URL- DB.pp , . , " MyApp" " " URL- myapp.com://sharedpage. ]


- ?

+5
3

, " " , ( ).

URL http://myapp.com/sharedpage, URL- Facebook http://myapp.com/share.htm?redirectUrl=sharedpage

share.htm - javascript, . , Android window.location.replace , / . .

<!DOCTYPE HTML>
<html>
<body>
    <script type="text/javascript">
        var redirectUrlRelativeToThisPage = ""; // Read off the querystring here
        var isAndroidDevice = (/android/gi).test(navigator.userAgent);

        if (isAndroidDevice) {
            // Android device. If the user isn't using a stock browser then window.location.redirect() doesn't always
            // trigger an Intent (and prompt to open Native app) so instead attempt to fake click a hyperlink with the
            // URL as this works more reliably (but not always).
            var linkToFakeClick = document.createElement("a");
            linkToFakeClick.href = redirectUrlRelativeToThisPage;
            var fakeMouseClickEvent = document.createEvent("MouseEvents");
            fakeMouseClickEvent.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
            linkToFakeClick.dispatchEvent(fakeMouseClickEvent);
        }
        // If we got here either we're not on an Android device or the fake click didn't work so just redirect normally
        window.location.replace(redirectUrlRelativeToThisPage);
    </script>
</body>
</html>

, , ( , ) "/ ", URL ( ) URL-.

+5

http://m.facebook.com/l.php:

<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="http" 
        android:host="m.facebook.com" 
        android:path="/l.php" />
</intent-filter>

URL , .

, , , . , , , . , ( , ), , http://m.facebook.com/l.php. facebook.

, Android , : https://code.google.com/p/chromium/issues/detail?id=235060

+1

Do you consider using Facebook defolation? http://developers.facebook.com/docs/mobile/android/deep_linking/

0
source

All Articles