Click here to Skip to main content
15,884,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
How can i navigate back to a page in my android app after loading an external site. 

1.Open app 

2.In app user will go to an external link 

3.External site has link,which take the user back to app. 

How can i go to my application . I have tried to give "file:///android_asset/www/package.html" in href but its not working at all . Please suggest me and thank you in advance.
Posted

1 solution

You need to implement a custom URL scheme.

You'd then embed a link with a scheme which is unique to your app such as:

myappname://information/to/be/passed/back

When your application installs the manifest tells the operating system which URL schemes your application wants to accept. The OS then starts listening for you and automatically loads your applications, passing in the full URL, when an appropriate URL is clicked/tapped.

A browser for example doesn't register a custom scheme. It registers http and https. This is how the operating system knows to give you a choice of browser when you click standard web links in content such as e-mail e.t.c.

This process is similar on both Android and iOS and luckily there's a plugin which standardises the API and simplifies this process for PhoneGap/Cordova.

EddyVerbruggen/Custom-URL-scheme · GitHub[^]

On a side note - You should never load externally hosted web content directly into the Cordova WebView. On iOS this is likely to get your application submission rejected.

Loading external webpages into your applications Cordova WebView gives that page full access to the device (Within the scope of the applications permissions).

If you need to load an externally hosted web pages you should exit to the system browser or if appropriate use the PhoneGap InAppBrowser.

InAppBrowser - Apache Cordova[^]

Alternatively if you're just looking to get content from the server to embed in your application then I'd just use AJAX to get the content and javascript to manage the view update. This gives you the benefit of being able to catch failed requests without your application crashing out with a 500, 404 or some other standard HTTP response error from which your user may not be able to recover from.
 
Share this answer
 
v5
Comments
Sradhanjali Behera 27-Jan-16 6:33am    
But i am getting error ,while running this code in cmd
cordova plugin add cordova-plugin-customurlscheme --variable URL_SCHEME=mycoolapp
can you plz tell me why the error "Error: Current working directory is not a Cordova-based project" is coming?
Stephen Hewison 27-Jan-16 6:41am    
Then you're in the wrong directory. You should be in the root of your cordova project. Where the main config.xml file is.
Sradhanjali Behera 27-Jan-16 6:56am    
I am using android studio to devlop this app.Root of my cordova project means ,which path ?I am not gettng you.
Stephen Hewison 27-Jan-16 8:24am    
When you create your cordova project you use the cordova create command on the command line. This creates a folder. The created folder is the root of your project.
Sradhanjali Behera 27-Jan-16 8:31am    
Ok.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900