Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9272923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:58:45+00:00 2026-06-18T15:58:45+00:00

I have an Android Phonegap/Cordova app that interacts with an ASP.NET MVC web application.

  • 0

I have an Android Phonegap/Cordova app that interacts with an ASP.NET MVC web application. I am trying to detect server side whether or not the web page is being loaded from a browser or from my Phonegap/Cordova app.

There are a few methods I have considered:

  1. Change the User Agent string. I found this stackoverflow link that describes a way to make that work. Unfortunately, it did not work for me. The request object did not have the custom user agent string.
  2. Include a custom header value. This can be done by modifying the cordova library (see this stackoverflow link.) Modifying libraries is usually a bad idea, though, since it becomes a maintenance problem in the future. (Update: this method didn’t work after the first request.)
  3. Add something special to the query string when loading the first page. A cookie could then be set. This is kind of an ugly solution compared to a simple header change.

Am I doing something wrong on the user agent string change? Or is there another method that would accomplish this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T15:58:46+00:00Added an answer on June 18, 2026 at 3:58 pm

    Looks like there’s a pull request for something similar (add “cordova/phonegap” to UAS)
    https://github.com/apache/cordova-android/pull/10

    Here is the heart of it.

    So I would extend DroidGap and override public void init(CordovaWebView webView, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient) :

    ...
    WebSettings settings = this.appView.getSettings();
    String userAgent = settings.getUserAgentString();
    // can append or redefine here
    userAgent += " PhoneGap/Cordova";
    settings.setUserAgentString(userAgent);
    ...
    

    Then you can use the extended DroidGap and have control over how you define the User Agent String.

    Just confirmed this works, here is the full code using the current Cordova implementation:

    package com.focusatwill.androidApp;
    
    import org.apache.cordova.CordovaChromeClient;
    import org.apache.cordova.CordovaWebView;
    import org.apache.cordova.CordovaWebViewClient;
    import org.apache.cordova.DroidGap;
    import org.apache.cordova.api.LOG;
    
    import android.util.Log;
    import android.view.View;
    import android.view.ViewGroup;
    import android.webkit.WebSettings;
    import android.widget.LinearLayout;
    
    
    public class DroidGapCustom extends DroidGap {
    
        /**
         * Initialize web container with web view objects.
         *
         * @param webView
         * @param webViewClient
         * @param webChromeClient
         */
        public void init(CordovaWebView webView, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient) {
            LOG.d("EVENT", "Custom DroidGap.init()");
    
            // Set up web container
            this.appView = webView;
    
            // Custom addition of user agent string
            WebSettings settings = this.appView.getSettings();
            String userAgent = settings.getUserAgentString();
            // can append or redefine here
            userAgent += " PhoneGap/Cordova";
            settings.setUserAgentString(userAgent);
    
            this.appView.setId(100);
    
            this.appView.setWebViewClient(webViewClient);
            this.appView.setWebChromeClient(webChromeClient);
            webViewClient.setWebView(this.appView);
            webChromeClient.setWebView(this.appView);
    
            this.appView.setLayoutParams(new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    1.0F));
    
            // Add web view but make it invisible while loading URL
            this.appView.setVisibility(View.INVISIBLE);
            this.root.addView(this.appView);
            setContentView(this.root);
    
            // Clear cancel flag
            this.cancelLoadUrl = false;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SCENARIO I have a small Android Phonegap/Cordova 2.3.0 application, I looked into /res/xml/config.xml file
I am using phonegap(cordova 2.1.0) for IOS/android app development. Every time i have to
We have written a Cordova / PhoneGap 2.2 application for Android and iOS 6
I have a Cordova/PhoneGap 2.0 based Android application, and I'm attemping to use intent-filters
I am trying to port a Phonegap/Cordova app to Android. It works on earlier
I develop an app for Android with Sencha Touch and Phonegap (cordova-2.0.0). I have
I have a phonegap app that works in android and ios but when I
I have developed the android phonegap application using html page and css. But My
I have developed a android application using phonegap. I have registered certain recievers which
I have a strange problem in my PhoneGap-based android app. On certain screens, the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.