I have 2 activities in my app, First Activity is simple editText and submit Button, When I press submit, it launches webView Activity and searches the keyword entered in the first activity. Now I want to open the first link Automatically in webview.
public class MainActivity extends AppCompatActivity {
WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient());
String query = "firebase";// Get the text from EditText here
String url = "https://www.google.com/search?q="+query;
webView.loadUrl(url);
}
}
Related
I have a problem. I created some app, which should open my website, but when I run the app on my phone, its ask me in which browser I want to open it(Google Chrome...). But I want that website is open in app, not in browser... I'm working with Android Studio 1.1.0... Here is my code in MainActivity.java:
public class MainActivity extends ActionBarActivity {
private WebView MyWeb;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyWeb = (WebView) findViewById(R.id.WebView);
MyWeb.getSettings().setJavaScriptEnabled(true);
MyWeb.getSettings().setSaveFormData(true);
MyWeb.loadUrl("http://www.mywebsite.com");
} }
P.S. I changed the url to the fake one...
Add this line of code before your MyWeb.loadUrl
MyWeb.setWebViewClient(new WebViewClient());
This worked for me.!
I want to read pdf files and display contents on TextView. is it possible ? or just show pdf into WebView or pdfViewer?
i want to do like it,
public class MainActivity extends Activity {
private TextView showText;
String url="http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showText= (TextView)this.findViewById(R.id.showtext);
showText.setText( ++ convertPdfTotext ++);
}
public void convertPdfTotext(View view)
{
}
}
If you want to use it in text view you can convert it with itext as string,but you'll loose formatting:
PdfTextExtractor parser =new PdfTextExtractor(new PdfReader("C:/Text.pdf"));
parser.getTextFromPage(3);
Use WebView instead and you can enable even zoom.
WebView mWebView=new WebView(MyPdfViewActivity.this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.loadUrl("https://docs.google.com/gview?embedded=true&url="+LinkTo);
My webpage is divided in various parts instead of loading full page, i want to load a part of that page div id = map_canvas.
Below code is giving me full page but i want only one part map_canvas
public class Jetbill extends Activity {
public WebView myWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.jetbill);
myWebView = (WebView) findViewById(R.id.webview);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadUrl("http://jetbill.biz/users/login.php");
}
}
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
android webview click opens default browser
I have an application that opens a website in webview on start, however I can't seem to figure out how to keep any URL's that a user clicked on from opening in the browser.
Is there anyway to load the clicked URL inside the webview app?
EDIT - Using the below solution I still get an error on the private class "Illegal modifier for the local class MainScreenActivity; only abstract or final is permitted"... even if I try to rename this I get the same error
public class MainScreenActivity extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_NO_TITLE);
WebView webview = new WebView(this);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://www.talk-of-the-tyne.co.uk");
setContentView(webview);
private class MainScreenActivity extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
}
Apologies if I am being thick about this, I just can't seem to get my head around this one
try this code:
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
i m getting a photo from the web,but i see it very large..how could i see it with zoom out?this is my code for webView:
public class gavros extends Activity {
WebView browser;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.efimerides);
browser =(WebView)findViewById(R.id.webview);
browser.loadUrl("http://...");
}}
Checkout WebView's setInitialScale method:
http://developer.android.com/reference/android/webkit/WebView.html#setInitialScale(int)