WebView won't execute site commands - java

I have a WebView that loads this WebSite
If you try to put an identification and click out of the box, it shows a little loading and tells if the identification is correct it shows a virtual keyboard within the site, not a device keyboard, if its incorrect it shows a error message, like this
Site showing error
However, if i put the same website on my WebView, it loads the site perfectly, but it won't execute these commands, if i put any identification and click out it doesn't shows the loading, it won't do anything.
Funny part is, if i do the same WebView in Xcode for iPhone, it does everything normally, even the commands, it checks for the identification, etc...
What i've tried
Turning on/off:
Javascript
Plugins(even deprecated)
My code:
package com.example.viskee.webview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView wbAba = (WebView) findViewById(R.id.wbAba);
wbAba.setWebViewClient(new WebViewClient());
wbAba.getSettings().setJavaScriptEnabled(true);
wbAba.loadUrl("https://ib.rendimento.com.br");
}
}
EDIT:
If i use
wbAba.setChromeClient(new ChromeClient);
it works fine, however i don't want to use ChromeClient because it adds an address bar, etc... I want my WebView to be FullScreen, show only the website

Have you try this:
WebView wbAba = (WebView) findViewById(R.id.wbAba);
wbAba.setWebViewClient(new WebViewClient());
wbAba.getSettings().setUseWideViewPort(true);
wbAba.getSettings().setLoadWithOverviewMode(true);
wbAba.getSettings().setJavaScriptEnabled(true);
wbAba.loadUrl("https://ib.rendimento.com.br");
and one final thing, don't forget to set internet permission on manifest.xml file:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Let me know, if this doesn't work.

I found a solution, all i had to do was:
wbAba.getSettings().setDomStorageEnable(true);

Related

How to embed WebView in Java in Android Auto

I'm new to Java and am currently developing an Android Auto app.
It's using WebView to display local HTML files.
I've tried many ways, but everything went wrong.
My App can start in Android Auto, but embedding WebView fails every time.
And the Internet is like empty on this subject.
Here is what I'm trying currently:
package com.example.webviewandroidauto;
import android.webkit.WebView;
import androidx.annotation.NonNull;
import androidx.car.app.CarContext;
import androidx.car.app.Screen;
import androidx.car.app.model.Template;
public class StartScreen extends Screen {
public StartScreen(CarContext carContext) {
super(carContext);
}
#NonNull
#Override
public Template onGetTemplate() {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView mywebview = (WebView) findViewById(R.id.webView);
mywebview.loadUrl("file:///android_asset/myresource.html");
}
}
Can someone please help me out?
Thank you!
Proof that my app starts in Android Auto: https://i.stack.imgur.com/OXC80.png

Redirect to a webpage while opening an android app

I need to develop an app which redirects users to my website right after the app was started.
Thats all I want in my mobile app.
I am using Android studio but I am not familiar with XML. So I am stuck there. Which code should I write to do this redirection? Hope you all can help me. Thank you.
First you need to import this:
import android.content.Intent;
import android.net.Uri;
In your MainActivity.java class, OnCreate Method you may add
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent i = new Intent(
Intent.ACTION_VIEW,
Uri.parse("http://www.google.com")
);
// Starts Implicit Activity
startActivity(i);
}
You can use a web view in XML file and load your url in it
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.google.com");

Android development noob: WebView usage

I've been following this series of Android Development Tutorials and I've encountered some problem trying to tweak one of the projects I've created.
Basically all I want to know is how to apply the WebView correctly in my project - in the easiest and most simple way possible.
What I've done:
enabled permission to the internet on the manifest
created the webview on the main_activity.xml
imported the WebView webkit to my MainActivity Java class
And all I've done after that is simply loading the url on my onCreated method like this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView v = (WebView) findViewById(R.id.weblol);
v.loadUrl("www.google.com");
}
However nothing seems to happen and the block of the WebView remains blank white
Care to explain to a noob what am I doing wrong ?
You should use http://www.google.com instead of www.google.com.
Only you to this,webview can notice this it is a URL.
Otherwise.you can use local file in webview ,like file:///android_asset/xxx in assets folder.
That's all.

output for System.out.print("Hello") in Android program

I want to see any variable (String var) value in my android program.
You can say for debugging purpose.
When I am printing anything using, say System.out.print("Hello")
Then I am unable find this output any where.
Do anyone have idea where to find this output.
Here is my code-
package com.test1.nus;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.out.print("Hello");
....
}
By default, the Android system redirects stdout (System.out) output to /dev/null, which means your messages are lost.
Instead, the common pattern to log debug strings in Android is the following
import android.util.Log;
Then at the top of your class YourClass
private static final String TAG = YourClass.class.getSimpleName();
And to log debug strings you need to call
Log.d(TAG, "your debug text here");
which in your case results in
package com.test1.nus;
import android.util.Log;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
private static final String TAG = MainActivity.class.getSimpleName();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "Hello");
....
}
Finally you can see your debug strings in Eclipse via
Windows > Show view > Other and select LogCat
and if required filter by the tag of YourClass.
However, if you really need to see messages written by System.out.println you need to tell Android to route them to logcat via the following shell commands
$ adb shell stop
$ adb shell setprop log.redirect-stdio true
$ adb shell start
and then you will be able to see your debug messages in Eclipse via LogCat view and the tag stdout.
You can get more details from the official documentation here http://developer.android.com/tools/debugging/debugging-log.html
Your output will be logged to logcat
Assuming you are using eclipse:
Window > Show View ---> Logcat (If this not visible, select other--Android--Logcat)
See this link: http://www.droidnova.com/debugging-in-android-using-eclipse,541.html
It will show some screen shots related to logcat. There you can find out your output message.
Follow this: http://developer.android.com/tools/help/logcat.html
If you want to check your output in the android emulator use Toast messages.
The result with system.out.println("....") will be displayed in logcat.
To check in android emulator/device.just do like this
Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_LONG).show();
I suggest you take a look at the android.util.log class. The Android developer pages has a good introduction for using it. (In fact, I just found this today since I'm learning Android programming myself.)
If you use the AVD s that will give you a more interesting experience than just print in the log. Here they have described all those things perfectly.
You are better off using Logs if it is for debugging purposes.
There are various methods available like Log.v() Log.d() Log.i() Log.w() and Log.e() for verbose, debug, info, warn and error logs respectively.
Then you can check the logcat while debugging the application.
For further reference, go here.

how to view youtube video

I am finding great difficulties to view YouTube videos in my app.
here is my code:
package com.example.webvideo;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class WebVideo extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView vv = (VideoView) findViewById(R.id.videoView);
MediaController mc = new MediaController(this);
mc.setAnchorView(vv);
vv.setMediaController(mc);
vv.setVideoURI(Uri.parse("http://youtu.be/2OIOOb-0t44"));
vv.start();
}
}
The emulator is showing an error that the video cannot be played.
What am I doing wrong? Am I giving the URL in a wrong format?
I would expect that the URI you need to give is to the actual media file to be played. I wouldn't count on redirects working either... and anyway that redirect you give seems to point to a YouTube web page, which I sure wouldn't expect the video player to be able to render.
http://youtu.be/2OIOOb-0t44 is certainly an invalid URL. Maybe you meant http://youtube.com/watch?v=2OIOOb-0t44?
The URL you are using is for the webpage where you can view it, not for the video itself. The embedding URL appears to be http://www.youtube.com/embed/2OIOOb-0t44, but I think it's HTML5, not flash... you may have to go old school and track down an AVI or MPEG file.

Categories

Resources