Accessing external website from PhoneGap application

I wanted to create a PhoneGap application, which instead of pointing to a HTML page inside the application should open my blog site http://wpcertification.blogspot.com these are the steps that i followed to build the application, you can download it from here
  • I followed the instructions in Getting Started with Android to build application that points to index.html inside the application, i tried it once to make sure that it works
  • Then i changed the HelloCordovaActivity like this so that it points to http://wpcertification.blogspot.com
    
    package com.webspherenotes.cordova.sample;
    
    import org.apache.cordova.DroidGap;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    public class HelloCordovaActivity extends DroidGap {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            super.loadUrl("http://wpcertification.blogspot.com");
        }
    }
    
    The onCreate() method is calling super.loadUrl("http://wpcertification.blogspot.com"); so that http://wpcertification.blogspot.com page is opened in the WebView as soon as application starts
  • The default configuration of the PhoneGap application disallows opening of any external URL so i had to change the cordova.xml like this to allow access to http://wpcertification.blogspot.com
    
    <?xml version="1.0" encoding="utf-8"?>
    
    <cordova>
     <!--  
     access elements control the Android whitelist.  
     Domains are assumed blocked unless set otherwise
      -->
    
        <access origin="http://127.0.0.1*"/> <!-- allow local pages -->
     
     
     <access origin="http://wpcertification.blogspot.com" />
     
     
     <!-- <access origin="https://example.com" /> 
     allow any secure requests to example.com -->
     <!-- <access origin="https://example.com" subdomains="true" /> 
     such as above, but including subdomains, such as www -->
     <!--  <access origin=".*"/>   
     Allow all domains, suggested development use only -->
    
        <log level="DEBUG"/>
        <preference name="classicRender" value="true" />
    </cordova>
    
    Take a look at XML comments in this file for syntax on how to allow access to external URLs
Now the application is ready and when i launch it i can see my blog being opened like this

4 comments:

Tuấn Hoàng Anh said...

why "" error "Description Resource Path Location Type Attribute is missing the Android namespace prefix"

Bangalore Web Guru said...

I am a regular user of your post, this one also was very interesting and well written. keep sharing the great work Web Design Agency in Bangalore | Website Developers in Bangalore

Jason Borne said...

Nice post and great content.
Avast Customer Support is here to help you out with the whole procedure to Download Avast Antivirus online, We not only fix your Avast Support related issues but will guide with how to get started with your new Avast product once it gets installed successfully. We at Avast Tech Support provides service to protect your PC from potential online threats and external attacks like viruses, Trojans, malwares, spywares and phishing scams. And Avast Refund. Call on our Avast Phone Number

Gmail Customer service is a third party technical support service for Gmail users when they face any technical issue or error in their Gmail account. Our Gmail Customer Support team solves issues like forgot Gmail account password, Gmail configuration or Sync issues, recover deleted emails and many more. Toll Free number (800) 986-9271

How you install or reinstall Office 365 or Office 2016 depends on whether your Office product is part of an Office for home or Office for business plan. If you're not sure what you have, see what office com setup products are included in each plan and then follow the steps for your product. The steps below also apply if you're installing a single, stand-alone Office application such as Access 2016 or Visio 2016. Need Help with office setup Enter Product Key? Call 1-800-000-0000 Toll Free
Norton Tech Support is a third party service provider and not in any way associated with Norton or any of its partner companies. We offer support for Norton products and sell subscription based additional warranty on computer and other peripheral devices. Call our Toll Free number 1 855 966 3855
Other Services
Norton Toll Free , Office-Setup , office.com/setup.

Designpluz said...

Great list. I know many of them, but have now bookmarked several new ones. Thanks!I like This Blog Posting. I Will Recommend This Post to Our Friends.Web Design Sydney, Logo Design Sydney