I am developing an Android application which uses WebView, and I would like to open a link in the app. The problem I have come across is that each of our customers use a different URL and is set via a preference in the android application. From, what I understand you have to set a link in the android manifest. Is this still achievable to have a link open in the application?
In order to open a link in the app just make sure to have an Activity that has a WebView on its layout. Then, in your activity do something like this:
WebView webview = (WebView) findViewById(R.id.your_web_view);
webview.loadUrl("http://your.url/");
Just read the user preference that stores the URL before calling loadUrl() and you're all set
You need to add a webview and give it an id. And then do this in your code:
//Identify the webview
WebView web_view = (WebView)findViewById(R.id.web_view);
//start web client
web_view.setWebViewClient(new WebViewClient());
//Load URL
web_view.loadUrl("your url");
And don't forget to add this line in your AndroidManifest.xml file :
<uses-permission android:name="android.permission.INTERNET" />
Hope it works!! :)
Related
I am writing an Android App for a charity, and would like to be able to display the charity's facebook feed within the App. I don't want it to go through the phone's web browser, nor the facebook app.
I read on the developers.facebook.com how to add facebook's android sdk to the app's build gradle. But what I can't find is code for a simple android activity that will display the facebook timeline. I don't have time to dive deep into facebook's sdk to fiigure it out. And the last thing I want to do is reinvent the wheel.
Can anyone point me towards some code for a simple activity to display a facebook timeline? Any help will be greatly appreciated.
I'm not home so I can't test this right now but it should work.
In your layout file, put a webview like so:
<WebView
android:id="#+id/mWebView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Then in the onCreate method:
WebView mWebView = (WebView) findViewById(R.id.mWebView);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://LinkToFacebookPage.com/");
And finally, in your manifest file put the following permission before < Application >
<uses-permission android:name="android.permission.INTERNET" />
i need to know how to load Survey Form dynamically from my web url and show it in android.
For that you have to use WebView.
in your OnCreate() method use following code
WebView browser = (WebView) findViewById(R.id.webview);
browser.loadUrl("http://www.tutorialspoint.com");
Tutorial for implementing the complete solution : Open URL in WebView.
Basically, I have a Webview that points to an internal "note.html" file.
In this note.html file, which is written in HTML, I have a website HREF, but when I click on it on a device, I get an error message:
"the webpage at file:///android/asset/www.blahblah.com might be temporarily down ...etc."
I am somewhat aware that I have to parse the URL or something of that nature, and would really appreciate a response on how to get the HREF link to open the proper web link to a browser.
the variable:
private static final String tip_URL = "file:///android_asset/tip.html";
the onCreate:
WebView mywebview = (WebView) findViewById(R.id.webview); mywebview.loadUrl(tip_URL);
this works fine on a mobile device, however, in the tip.html there is a link to a website, and when clicked i want a browser to open to go to that site..it is not another local page..
My native app includes a WebView, and the WebView loads a web page off web. For example, the html is loaded from
http://dongshengcn.com/test.html
It seems any page loaded from web (instead of local) can not load any file from local device.
My question is:
Is it possible for a http://dongsheng.com/test.html loaded to a webview (as part of native app) to access file on local device?
Here are a couple of things to try:
To use local files you need to place them in your project's assets folder and invoke them using URLs such as file:///android_asset/. For example, if you add mypage.html in your assets folder, then you can invoke it in the webview with file:///android_asset/mypage.html.
Check to make sure that you have the appropriate webview permissions in your Manifest. For the webview to work correctly, you need:
<uses-permission android:name="android.permission.INTERNET" />
Take a look at the following app on Github, which as a bonus also fixes a couple of bugs with the webview in Honeycomb and ICS. It is a full example on how to use the webview with local files:
https://github.com/bricolsoftconsulting/WebViewIssue17535FixDemo
EDIT: Addendum after question clarification:
Yes, it is possible to load a local page from the web, but you must use a trick to bypass the browser's security measures.
Replace the file://android_asset/ portion of the URLs with a custom scheme (e.g. file///android_asset/mypage.html becomes myscheme:///mypage.html), and place these custom scheme URLs in your page. Implement WebViewClient's shouldOverrideUrlLoading, check if the URL begins with the custom scheme and if so redirect to the local page using webview.loadUrl.
mWebView.setWebViewClient(new WebViewClient()
{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (url != null && url.startsWith("myscheme://"))
{
String newUrl = url.replace("myscheme://", "file://android_asset/");
mWebView.loadUrl(newUrl);
return true;
}
return false;
}
}
I am trying to show
http://www.google.co.jp/m/place#ipd:mode=home
website thru WebView in Android emulator but I am not seeing the web
site and seeing only blank space under the place tag of the page.
I am able to see other sites like www.google.com.
Do I need to enable more settings for the google place page?
Permission in the manifest
<uses-permission android:name="android.permission.INTERNET" />
Code
WebView view= (WebView) findViewById(R.id.view1);
View.getSettings().setJavaScriptEnabled(true);
View.getSettings().setBuiltInZoomControls(true);
View.getSettings().setSupportZoom(true);
View.loadUrl(" http://www.google.co.jp/m/place#ipd:mode=home");
You need to do
view.getSettings().setAppCacheEnabled(true);
view.getSettings().setDomStorageEnabled(true);
on the setting object. That fixed the problem for me.