I 'm trying to display a pdf into my app ,but the method setpluginsEnabled() doesn't exists and his substitute it's deprecated what i have to do?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mostrar_pdf);
WebView mWebView=new WebView(MostrarPDF.this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.getSettings().setAllowFileAccessFromFileURLs(true);
mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.loadUrl("https://drive.google.com/viewerng/viewer?embedded=true&url=pdfpathfile");
setContentView(mWebView);
}
You can use this library
android-pdfview from JoanZapata
Edit : you can search in GitHub about your problem.
Android+PDF in GitHub
Related
I am loading html5 game from Advance webview library. One game is working fine but other game gets stuck after clicking on play button.
I opened the same game on chrome & other browsers (in Android), its working fine there. So the problem is not with the game but with my code.
I have attached the code below. Please check and let me know what is the issue?
Java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
setContentView(R.layout.activity_game);
Intent intent = getIntent();
String url = intent.getStringExtra(Constants.INTENT_URL_KEY);
isItemPurchased = intent.getBooleanExtra(Constants.INTENT_ITEM_PURCHASED, false);
AdvancedWebView mWebView = findViewById(R.id.webView);
mWebView.setListener(this, this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
mWebView.loadUrl(url);
}
I have a web page with a basic form (like a newsletter subscription).
The user sends its information and gets a success page with a link to the form submission page. If he doesn't click on the link the page will be automatically redirected after 5 seconds.
<meta http-equiv="refresh" content="5;url=www.site.com" />
So far so good! It works as expected in both desktop and mobile browsers.
Then I created an android app (min API SDK 21) with a web view to load the site.
The problem is that the auto refresh isn't working inside the web view...
Am I missing something? I'm trying to avoid the javascript hack...
Thanks for your time!
EDIT
I notice that when I click on the new form submission page link it opens the default browser instead of rendering it on the web view!
After searching for the problem, I came to a solution by resetting the URL on URL loading.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
mWebView = findViewById(R.id.webview);
mWebView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
mWebView.loadUrl(url);
return true;
}
});
mWebView.loadUrl(url);
}
It's working, but I think it can be improved.
My initial problem was that I wasn't setting a WebViewClient.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
mWebView = findViewById(R.id.webview);
mWebView.loadUrl(url);
}
Thus, I think I just need to add a WebViewClient and it'll work
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
mWebView = findViewById(R.id.webview);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl(url);
}
Note, and if we want javascript to work we need to enable it
mWebView.getSettings().setJavaScriptEnabled(true);
I am working on my first android project which is based on Google Forms.
I've done pretty much everything except my main part which is showing forms in webview. The form is getting display but the Sign In button is not clickable.
public class cadexpo extends AppCompatActivity {
private static WebView browser;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cadexpo);
browser = (WebView) findViewById(R.id.webView);
browser.getSettings().getJavaScriptEnabled();
WebSettings browser = browser.getSettings();
browser.loadUrl("https://drive.google.com/open?id=1VLKIncq9bTJnWqxbOHc3foTeSLykP7AQyL0Si1cIQ1I");
Please help me in fixing it.
Enable javascript for webview
WebSettings webSettings = browser.getSettings();
webSettings.setJavaScriptEnabled(true);
I'm trying to make an app with a webview of facebook.com, i want to load custom css but i don't know how. I searched on Google but found old tutorials and i read that it has changed in Android Studio 2.0
Here is my code:
private WebView myWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myWebView = (WebView)findViewById(R.id.webView);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadUrl("https://www.facebook.com/");
myWebView.setWebViewClient(new WebViewClient());
}
I'm new with Android, so maybe someone can help me.
I have loaded an external URL in WebView.
I want that the links from my site http://www.domanin.com/about.php to open in WebView and the external link http://www.anotherdomanin.com/sample.php to open in default browser.
My code:
#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.domanin.com");
}