5

There is an app on Google Play which is embedding my website in a webview. The app does nothing else, and includes a 3rd party monetization feature.

I want to detect when users are accessing my site via the app, so that I can show a message.

I haven't however been able to find a way to distinguish between the Android mobile browser and the app, as the user agents are the same.

Is there any known method to detect a webview?

Thanks.

Aracem
  • 7,227
  • 4
  • 35
  • 72
Nick
  • 326
  • 4
  • 12
  • possible duplicate of [Android, webview user agent vs browser user agent](http://stackoverflow.com/questions/12727117/android-webview-user-agent-vs-browser-user-agent) – g00dy Jul 22 '13 at 08:46
  • I didn't try it, but the solution of this question looks good : http://stackoverflow.com/questions/16383776/detect-in-app-browser-webview-with-php-javascript. It uses the http header of the request. – Stephane Mathis Jul 22 '13 at 08:53
  • I did see the other questions but none of those solutions worked. They mention an "X-Requested-With" header but unfortunately this isn't being sent by the app (perhaps it can be disabled by the app author) – Nick Jul 22 '13 at 09:04

3 Answers3

8

Unfortunately, the answer is no, there isn't a way to distinguish between the Android mobile browser and another webview-based app.

Unless the app developer elects to modify the user agent, of course.

stumpped
  • 231
  • 2
  • 7
1

If you know the App ID of the app displaying your website through a webview, you can use PHP to detect if your site is being accessed through the app rather than a mobile browser by using the $_SERVER global array.

<?php

    $app_id = "com.domain.appname";
    $using_app = ( $_SERVER['HTTP_X_REQUESTED_WITH'] == $app_id ) ? TRUE: FALSE;

    if ( $using_app ) {
        echo "Using app message.";
    }

?>

You can then use the $using_app variable to control content output and display a custom message.

This is all assuming of course you are server scripting your site via PHP.

McClint
  • 101
  • 5
0

You can also flag the app as copyright violator and ask Google to remove it from the market...

eladzaa
  • 168
  • 1
  • 2
  • 9