Here is what I am doing:
I'm building a webpage which I'm going to use in [an] android [app] for [the main] UI.
I want [to] interact with the android code while working the webpage. What I need is when I click a button on the webpage on an android phone a piece of android code should get executed. Normally we use direct buttons from android but in this app I need it that way.
Please drop in any suggestions.
Thank you
You need to read the documentation: Building Web Apps in WebView
Related
So, I'm working on an app which is a web based app. The apps code base is mostly written in JavaScript and HTML. The app is also available on a native app which basically only contains a WebView displaying the HTML and JavaScript code.
My problem is that when a user is on the Android native version and launching an external link, it opens perfectly in the Android WebView but there is some cases where the launched page not is scrollable and other strange stuff.
So to solve this issue I need the native app to launch the in-build browser in the Android phone. Basically, the exact same effect that startActivity(new Intent(ACTION.VIEW,URI)) has.
The thing is that I can't modify the Android version though all the logic is written within the web app..
My question is:
Is there any way to simulate:
startActivity(new Intent(ACTION.VIEW,URI))
in JavaScript to get out of the native app and launch the browser instead?
I build a webapp and I have social links in my webapp.
I am facing an issue regarding this. If I am having facebook installed in my device then on click of the share link it should open the native app instead of opening in browser.
And incase if I doesnt have any native app installed then it should automatically redirect to browser.
Here it is the code what I have tried:
Javascript:
if(isAndroid){
fb://profile//www.facebook.com/sharer/sharer.php // to open in native browser
http://wwww.facebook.com // to open in web browser.
}
How do I handle this urls...
Please help me out.
This is not possible, for privacy reasons.
See This answer
You can make Hybrid Application.
What you just need to do is ADD WEB INTERFACE which will make call to native source code through javascript and also get return value.
So you can write native function which will return if application is installed. Once you set this interface you can use it further for open that app and passing intent and all that.
You can do it easily. Start Here:
https://developer.android.com/guide/webapps/webview.html
I was trying the Geolocation example from the below link.
http://docs.phonegap.com/en/1.7.0/cordova_geolocation_geolocation.md.html#Geolocation
I copied the entire content from the first 'Full Example' and saved that file as an HTML. When I opened it in Chrome (desktop) and Android phone inbuilt browser(default), I got the following three alerts on both chrome and android phone.
gap:["Device","getDeviceInfo","XXXXXXXXXX"]
gap:["NetworkStatus","getConnectionInfo","XXXXXXXXXX"]
gap:["App","show","XXXXXXXXXX"]
I clicked 'Cancel' first time and even tried 'Ok' but, nothing happens. If I click 'OK' on all three alerts on my Android Phone, the page goes all white.
So I googled it and found couple of answers on Stack Overflow suggesting:
To remove the Cordova JS file for the desktop browser
Add android specific JS from the Cordova.
So I tried both but none of them worked. Latest, I tried the following solution.
I downloaded the Cordova package (3.0.0), there was a cordova-android.zip which had the cordova.js file at the following path.
/cordova-android/framework/assets/www/cordova.js
So, now my script element looks like this:
<script type="text/javascript" charset="utf-8" src="/cordova-android/framework/assets/www/cordova.js">
After modified the <script> element as above, I don't get alerts in Chrome, but I still get following NEW alerts on my Android phone.
gap:["PluginManager","startup","Plugin ManagerXXXXXXXXXX"]
gap:["App","show","XXXXXXXXXX"]
Code: 1, message: User denied Geolocation.
So, now I have following questions:
How do I solve this problem (to run the HTML page without alert on all devices/browser)?
Any idea on why did my alerts change after changing the cordova.js file?
Regards,
Rumit
Your problem is that you're using cordova.js as if it's a JS library like jQuery, but Phonegap (Cordova) is a hybrid framework not a mobile browser framework (see here for clarification). It's not intended to be used as a standalone JS library in a webpage, but in conjunction with a native Phonegap library in order to build a native application. If you created your page as a Phonegap app and built it for Android, you would be able to (and need to) allow the app permission to use geolocation.
Phonegap apps are implemented via a native WebView and in the case of the Geolocation API, Phonegap will use only use its own implementation if the device doesn't already have a native W3C implementation (which Android does).
So the point is: either create a proper Phonegap app for Android by following the platform guide or simply don't use the Phonegap JS at all since you can call the Android browser's geolocation API (navigator.geolocation) directly from Javascript in your webpage - you don't need Phonegap's JS file to allow you to do this (have a look at the answer to this question).
I am using an hybrid android app from geyser.
I want to inform the user about the possibility to download this app, if he enters the mobile version of my website. the thing is, in the app runs a browser which views almost the same content as the mobile website.
how can I detect with JS if I am running in the App-Browser and not on the normal Browser?
I don't want to show the download Link of the App in the App.
Thanks
What you could do is have a javascript function on your page like
setAndroidApp=function(){
isAndroidApp=true;
}
and then, when you load your site through the android version (assuming you're using the Android WebView class ), you could make the function run when loading the page in the following manner
webview.loadUrl("javascript:setAndroidApp()");
in which case, you'd have isAndroidApp set to true for the rest of your code if it's seen from the android app.
I want to call android application on clicking of button on some website from mobile.
For example,
When I click the web link, its call to android application if installed. Otherwise its redirect to specific application download on Android Market place.
Thanks in advance.
G. Padmanabhan.
You need to implement an Intent Filter. Read the documentation at the following link:
http://developer.android.com/guide/topics/intents/intents-filters.html#ifs