Android webview doesn't stream dropbox video - android

I am trying to stream a video stored on dropbox on android's webview but only a blank space is
displayed, my code is below :
activity_web_view.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/webView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/tview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/webView"
android:text="Description" >
</TextView>
</RelativeLayout>
public class WebViewA extends Activity {
private WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view);
webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://www.dropbox.com/s/XXXX/video.mp4?dl=0?client_id=XXXX");
}
}
I have also tried the following Urls on webView.loadUrl(), but none
of them work, only a blank space appears :
"https://dl.dropbox.com/s/XXXX/video1.mp4?dl=0?client_id=XXXX"
"https://dl.dropbox.com/s/XXXX/video2.mp4?dl=1?client_id=XXXX"
"https://dl.dropboxusercontent.com/s/XXXX/video1.mp4"
"https://www.dropbox.com/s/XXXX/video1.mp4?dl=0"
if I try http://www.google.com it works, I have also seen some tutorials
with dropbox addresses that have an 'u' instead of an 's' like
"https://www.dropbox.com/u/..."
does WebView only works with dropbox urls with an 'u', if so how can I
get that type of address.

Related

Problem: Loading Mapbox in Webview (Android Studio Project)

I have an html file in my website:
http://manizani.ir/hamyar_gas_php/map/map_app.html
I want to show it on my Android Application. I created an Activity and use a Webview to load above url. But nothing is loaded and it shows me just an empty activity.
I can load any other web pages successfully, but not about my url.
Please help me to solve it.
Thanks a lot
activity_map_web.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapWebActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<WebView
android:id="#+id/webview_intro"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</WebView>
</LinearLayout>
</RelativeLayout>
//////////////End of file//////////////////
MapWebActivity.java :
public class MapWebActivity extends AppCompatActivity {
WebView WV;
String url = "";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_web);
try {
WV = (WebView) findViewById(R.id.webview_intro);
WV.getSettings().setLoadsImagesAutomatically(true);
WV.getSettings().setJavaScriptEnabled(true);
WV.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
WV.getSettings().setBuiltInZoomControls(true);
WV.getSettings().setDomStorageEnabled(true);
WV.getSettings().setAppCacheEnabled(true);
WV.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
WV.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
WV.setWebViewClient(new WebViewClient());
url="http://manizani.ir/hamyar_gas_php/map/map_app.html";
WV.loadUrl(url);
} catch (Exception ex) {
Toast.makeText(this, ex.toString(), Toast.LENGTH_SHORT).show();
}
}
}
Mapbox use WebGL and may be is not support on your device.
webview log :
[INFO:CONSOLE(31)] "Error: Failed to initialize WebGL", source: https://api.mapbox.com/mapbox-gl-js/v2.2.0/mapbox-gl.js (31)
more at here

Nest ScrollView

there are two webviews in scrollview.
<ScrollView>
<LinearLayout>
<WebView></WebView>
<WebView></WebView>
</LinearLayout>
</ScrollView>
I want to make two webviews looks like one webpage. currently, my solution is make webview's height equal to webview's contentHeight. and disable scrollability of webview. but for very big html. it's not a good solution. webview has to render the whole html. I want to use nestedscrollview. make two webviews' height equals to nestedscrollview's height. but I dont known how to deal the events.
Try this to make two WebView looks like one webpage.
public class MainActivity extends Activity {
String url = "http://www.yahoo.com";
String url1 = "http://www.google.com";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("MainActivity", "Activity one");
WebView webview = (WebView) findViewById(R.id.webView1);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewController());
webview.loadUrl(url);
WebView webview2 = (WebView) findViewById(R.id.webView2);
webview2.getSettings().setJavaScriptEnabled(true);
webview2.setWebViewClient(new WebViewController());
webview2.loadUrl(url1);
}
}
XML code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<WebView
android:id="#+id/webView2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
WebView client
class WebViewController extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}

webView in android open the website in web instead of webview

when I run this code, "google.com" open in web application (for examaple google chrome) and not in the webView in the dialog.
It's does work OK with some urls.
Why?
final Dialog dialog=new Dialog(this.activity,android.R.style.Theme_Black_NoTitleBar_Fullscreen);
dialog.setContentView(R.layout.full_page_ad_between_chapters);
WebView webView = (WebView) dialog.findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://google.com");
R.layout.full_page_ad_between_chapters :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="350dp"
android:layout_height="1000dp"
android:layout_margin="5dp"
android:orientation="vertical" >
<Button
android:id="#+id/fullPageAdBetweenChaptersClose"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:text="סגור" />
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
You need to override the method shouldOverrideUrlLoading() on your WebViewClient.
WebView webView = (WebView) dialog.findViewById(R.id.webView1);
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// check if we want to open the url into the WebView
if (iWantToOpenTheUrlIntoTheWebView(url)) {
return false;
}
// let the system handle the url outside of the app
return true;
}
});

How to load url of phonegap in native webview not in cordova webview?

I am trying to load url inside my custom webview
webview.xml-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none">
<WebView
android:id="#+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</ScrollView>
</RelativeLayout>
and here is my classfile
public class AppDev extends CordovaActivity implements WLInitWebFrameworkListener {
private WebView webview;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
WL.createInstance(this);
WL.getInstance().showSplashScreen(this);
WL.getInstance().initializeWebFramework(getApplicationContext(), this);
webview = (WebView)findViewById(R.id.webView);
}
public void onInitWebFrameworkComplete(WLInitWebFrameworkResult result){
if (result.getStatusCode() == WLInitWebFrameworkResult.SUCCESS) {
// super.loadUrl(WL.getInstance().getMainHtmlFilePath());//
webview.loadUrl(WL.getInstance().getMainHtmlFilePath());
} else {
handleWebFrameworkInitFailure(result);
}}
loading url in webview is producing following error-
com.worklight.common.Logger$UncaughtExceptionHandler
java.lang.NullPointerException
com.worklight.common.Logger$UncaughtExceptionHandler(com.AppDev.AppDev.onInitWebFrameworkCo mplete(AppDev.java:49)
is there anyway to load url in custom webview not in cordova?
Any Help :(
Did you try following the Integrating Server Generated Pages in Hybrid Applications training module and sample application?
The module explains how to bring up a webview and display an external website in it (and return back to the application's webview).

Getting errors while trying to run WebView application

I am creating an application in which I have to use webView and display a HTML file saved in application in assets folder. This is my mainActivity code.
public class MainActivity extends Activity {
WebView browser;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
browser = (WebView)findViewById(R.id.wv1);
browser.loadUrl("file:///android_asset/test.htm");
WebSettings webSettings = browser.getSettings();
browser.getSettings().setJavaScriptEnabled(true);
setContentView(browser);
}
}
and this is my xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Test Application"
android:gravity="center_horizontal">
</TextView>
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/wv1"
android:layout_marginTop="3dp">
</WebView>
whin I am trying to run this application , it goes crash..
can any one please help me to find out what is the mistake i am doing.
You cannot call setContentView(browser) because browser is already a child of another view -- the LinearLayout.
If you don't need the other views, just change the layout xml file and remove them, leaving only the WebView. Otherwise, remove the setContentView(browser) line.
You're using setContentView() twice and supplying the view that already has a parent. That is why it is giving you the error saying call removeView() on the child's parent first. So remove setContentView(browser).
Your code should look like this.
public class MainActivity extends Activity {
WebView browser;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
browser = (WebView)findViewById(R.id.wv1);
browser.loadUrl("file:///android_asset/test.htm");
browser.getSettings().setJavaScriptEnabled(true);
}
}

Categories

Resources