I'm trying to create a WebView app that shows a meteor web app using Tiago Scolari's sample.
When i load the apk in my phone i see the background changes but the log in button doesn't show.
Anyone has a clue how to make this work?
--Edit:
Adding -
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setDomStorageEnabled(true);
- shows me the log in button and gets me to the facebook log in.
After logging in using facebook i'm presented with a white screen.
Any more advice?
Some code:
main.xml (layout):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mainWebView">
</WebView>
</LinearLayout>
AndroidMobileAppSample.java (java wrapper):
package tscolari.mobile_sample;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class AndroidMobileAppSampleActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView mainWebView = (WebView) findViewById(R.id.mainWebView);
WebSettings webSettings = mainWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setDomStorageEnabled(true);
mainWebView.setWebViewClient(new MyCustomWebViewClient());
mainWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
mainWebView.loadUrl("http://pastime.meteor.com/");
}
private class MyCustomWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
}
}
oke I just tested it on my 2.3.4 android and yea there is no facebooklogin. Its a WebView problem. Changed the code and still the login dosent appear...
Related
I am programming an Android app with Java with Android Studio. My app shows the website on screen and I would like to notificate the articles I will publish in the future. How can I do this? I have OneSignal Push in my webpage, if it is useful for the process
MainActivity
package secretosdemalaga.com;
import androidx.appcompat.app.AppCompatActivity;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.onesignal.OneSignal;
public class MainActivity extends AppCompatActivity {
public WebView mywebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);
// OneSignal Inicializacion
OneSignal.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.init();
// Ver Web en la app
setContentView(R.layout.activity_main);
mywebView = findViewById(R.id.am_webview);
WebSettings ajustes = mywebView.getSettings();
ajustes.setJavaScriptEnabled(true);
mywebView.loadUrl("https://educacioninformatica.es");
mywebView.setWebViewClient(new WebViewClient());
}
//Cerrar la app o volver atras
#Override
public void onBackPressed() {
if (mywebView.canGoBack()) {
mywebView.goBack();
} else {
super.onBackPressed();
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/caparefresco"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="#+id/am_webview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
Goal
To create a reduced TvView that displays on top of a WebView.
This is specifically for live TV.
(I've seen numerous solutions that address streaming content, but this is intended for video that's delivered through the coaxial cable.)
Where I'm At Now
The WebView portion works fine, and I've learned that a RelativeLayout is required in order to layer views.
Also, TvView doesn't seem to be recognized, so I'm guessing that I'll probably need to use a SurfaceView instead.
activity_main.xml
MainActivity.java
Questions
I've seen the TvInput, example applications, but it's extremely excessive. I'm not trying to recreate the TvInput service, just leverage on existing framework.
Is it possible to simply call on the existing, TV service that's already on the Android device, and display it in a view?
If it is possible, how is it accomplished?
If it's not possible, what's the simplest method of implementing it? (repository links would be great.)
I've searched all over for answers but can't seem to find anything.
Thank you in advance for any assistance.
Code in Text Format
As requested by tung.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_browse_fragment"
android:name="com.company.app.MainFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.company.app.MainActivity"
tools:deviceIds="tv"
tools:ignore="MergeRootFrame" >
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TvView
android:id="#+id/TvView"
android:layout_width="816dp"
android:layout_height="404dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp" />
</RelativeLayout >
MainActivity.java
package com.company.app;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.media.tv.TvView;
import android.view.View;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebSettings;
public class MainActivity extends Activity {
private WebView mWebView;
private TvView mTvView;
private WebSettings mWebSettings;
#SuppressLint("SetJavaScriptEnabled")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
mWebView = new WebView(this);
mWebSettings = mWebView.getSettings();
mWebSettings.setJavaScriptEnabled(true);
mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
mWebView.loadUrl("http://10.28.98.150:1000/");
mWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
this.setContentView(mWebView);
mTvView = new TvView(this );
mTvView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
this.setContentView(mTvView);
}
#Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
String channelUrl="content://android.media.tv/channel/"+channelNumber;
mTvView.tune(mInputId, Uri.parse(channelUrl));
input id is available in TV database(refering to which source channel is coming from).
If you pass these info to tvview it will start playing.
here i have a question. I have already make my blog app. But, when i run this app, suddenly it crashed. Here my source code
package blog.app;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class MainActivity extends Activity
{
private WebView myWebView;
private WebSettings myWebSettings;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView myWebView=(WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://teknorats.blogspot.com");
WebSettings myWebSettings=myWebView.getSettings();
myWebSettings.getJavaScriptEnabled();
myWebView.setWebViewClient(new WebVewClient());
}
private static class WebVewClient extends WebViewClient {
public WebVewClient() {
}
}
public class WebAppInterface{
Context mContext;
WebAppInterface(Context c) {
mContext=c;
}
private WebAppInterface() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public void showToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.addJavascriptInterface(new WebAppInterface(),"Android");
}
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the Back button and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
myWebView.goBack();
return true;
}
// If it wasn't the Back key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}
}
And this is the xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/webview"
android:src="#drawable/tr_launcher"
>
</LinearLayout>
Please, i need your correction with that code.
If you ask where i got this code, i got this code from here http://developer.android.com/guide/webapps/webview.html
It seems that in your xml file LinearLayout tag has id webview and you are trying to get
cast LinearLayout to WebView.
So change
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/webview"
android:src="#drawable/tr_launcher"
>
</LinearLayout>
to
<Webview xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/webview">
</Webview>
and you has already defined myWebView as class variable so change
WebView myWebView=(WebView) findViewById(R.id.webview);
to
myWebView=(WebView) findViewById(R.id.webview);
I am new to android, I have created a simple app to load a flash player into
a webview. My flash player contains a presentation which is saved in 2 folders in the
assets
folder 1 is Data
folder 2 is Player
and my player.html
The app get installed into the tablet and starts running but once the loading bar get
half way trough it, it stay like that without completing.
This is my Activity Java file
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity
{
final Activity activity = this;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_main);
WebView webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginsEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
activity.setTitle(R.string.app_name);
}
});
webView.setWebViewClient(new WebViewClient() {
#Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
// Handle the error
}
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
webView.loadUrl("file:///android_asset/player.html");
}
}
And Here is my XML file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|top"
android:orientation="vertical"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="HTML in WEB View"
tools:context="MainActivity" />
<WebView
android:id="#+id/webView"
android:hardwareAccelerated="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
I have the hardware accelerated as true on the manifest
Can someone please let me know where the problem could be.
My assumptions will be
Need to grant file access to the asset folder?
Do I need to put all my files in the assets folder with no subfolder?
Is Webview waiting for me to click on an invisible pop-up window allowing flash to
access the files?
Your help is very much appreciated.
The application that generated the flash files came back with an answer stating that it is not compatible with android development.
I am creating a ViewFlipper that flips thru WebViews: I have no problems running the app if I place the WebViews within the main.xml. Since I will be using a multiple count of Web views, I decided to break them up into separate XML files. When I do this using the include android:id="#+id/myWebView001" layout="#layout/pg001" within the ViewFlipper of the main.xml, I get an force close when the app starts.
Please look thru the following code and if you have any suggestions for this to work correctly, it will greatly appreciate it. Thnx again!!
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ViewFlipper"
android:layout_width="fill_parent" android:layout_height="fill_parent" >
<include android:id="#+id/myWebView001" layout="#layout/pg001" />
</ViewFlipper>
main.java:
package com.aero.ac4313;
import android.app.Activity;
import android.os.Bundle;
public class main extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//set your content view, this will be your layout
setContentView(R.layout.main);
}
}
pg001.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myWebView001" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
Pg001.java:
package com.aero.ac4313;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class Pg001 extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//set your content view, this will be your layout
setContentView(R.layout.pg001);
WebView mWebView = null;
mWebView = (WebView) findViewById(R.id.myWebView001);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("file:///android_asset/pg001.html");
}
}
The error is obviously simple. Your main activity class is null. I believe that he added Pg001.class without linking it with the main activity class. If you did add it on the manifest file then try again.