I am using video networking library - https://github.com/vimeo/vimeo-networking-java
But unable to play video in my android app. I don't know HTML iframe properly
In the official link, it shows-
Video video = ...; // obtain a video in a manner described in the Requests section
String html = video.embed != null ? video.embed.html : null;
if(html != null) {
// html is in the form "<iframe .... ></iframe>"
// display the html however you wish
}
What code I need to place here. I am unable to understand. If you know?
You donĀ“t need any library to use Vimeo player in Iframe.
Here is an example:
vimeoPlayer.java file:
public class vimeoPlayer extends AppCompatActivity {
private WebView myWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_vimeo_player);
myWebView=(WebView)findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.loadDataWithBaseURL("https://vimeo.com/47412289","<iframe src=\"https://player.vimeo.com/video/47412289\" width=\"100%\" height=\"100%\" frameborder=\"0\"></iframe>","text/html", "utf-8",null);
}
}
activity_vimeo_player.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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=".vimeoPlayer">
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
AndroidManifest.xml file
...
<uses-permission android:name="android.permission.INTERNET" />
...
Related
My app default language is Spanish (es). I have introduced a webview in XML. Prior to this change, the language is Spanish. After adding the webview, it's automatically showing English. How can I fix this issue or problem?
Thanks for helping in advance.
I already used below code too.
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUserAgentString(String.valueOf(Locale.SPANISH));
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="-5dp"
tools:ignore="WebViewLayout" />
You can dynamically add web view and initialize the language again after that.
llDynemic=(LinearLayout)findViewById(R.id.test);
WebView webView = new WebView(getContext());// webview in mainactivity
webView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
webView.setBackgroundColor(Color.TRANSPARENT);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadDataWithBaseURL(null, "<style>img{display: inline;height: auto;max-width: 100%;} a {color: #337ab7;}</style>" + newBody, "text/html", "UTF-8", null);
llDynemic.addView(webView);
// initialize the language here
and it will work
in activity have webView
#Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init here language again then
setContentView(R.layout.activity_terms_of_use);
After a lot of testing and following the advices from the other answers, I've finally fixed the issue.
Issues with WebView:
WebView have to be loaded dynamically in the activity. Loading from XML file via Activity#setContentView() won't work for the first time and localisation of the entire activity will break. However, subsequent launches or Activity#recreate() will work as expected.
Even if WebView is loaded dynamically, it won't work for the first time. Again, subsequent launches or Activity#recreate() will work properly.
Considering the issues above, the solution involves loading WebView dynamically and then, the immediate recreation of the activity.
ActivityWithWebView.java
public class ActivityWithWebView extends AppCompatActivity {
private WebView webView;
private static boolean firstTime = true;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
setContentView(R.layout.activity_with_web_view);
setSupportActionBar(findViewById(R.id.toolbar));
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) actionBar.setTitle(R.string.instructions);
// WebView has to be loaded dynamically to prevent in-app localisation issue.
webView = new WebView(this);
if (firstTime) {
// Recreate if loaded for the first time to prevent localisation issue.
recreate();
firstTime = false;
return;
}
LinearLayoutCompat webviewWrapper = findViewById(R.id.webview_wrapper);
webView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
webviewWrapper.addView(webView);
// Do other works.
}
}
activity_with_web_view.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?android:colorBackground" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.appcompat.widget.LinearLayoutCompat
android:id="#+id/webview_wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
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
I am trying to start a new activity with a WebView but when I try and load the activity, I am just brought to a white screen.
My Activity just has this as the code
public class TrainingVideos extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_training_videos);
WebView trainingWebview = (WebView) findViewById(R.id.web_trainingVideos);
trainingWebview.getSettings().setJavaScriptEnabled(true);
trainingWebview.loadUrl(url);
}
}
with my XML having
<FrameLayout 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:background="#color/octtan"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
tools:context="com.octitle.ryann.octmobile.TrainingVideos">
<WebView
android:id="#+id/web_trainingVideos"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:hardwareAccelerated="false" />
</FrameLayout>
And my manifest including
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
Try this
trainingWebview.getSettings().setJavaScriptEnabled(true);
trainingWebview.get settings().setLoadsImagesAutomatically(true);
trainingWebview.loadUrl(url);
Try to open the url in your app and not using your navigator
WebView trainingWebview = (WebView) findViewById(R.id.web_trainingVideos);
//New line to open the url in your app
trainingWebview.setWebViewClient(new WebViewClient());
trainingWebview.loadUrl(url);
trainingWebview.getSettings().setJavaScriptEnabled(true);
It turns out that it was an issue with self signed certificates contacting the server I was using.
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.
I am new to android development and i'm doing a an app where i need to embed an iframe in android's webview..
iframe sample is
<iframe src="//e.infogr.am/chart-61108188168" width="550" height="680" scrolling="no" frameborder="0" style="border:none;"></iframe>
Can you just set up a simple webview pointing to the iFrames url like so?
Create a webview in the xml:
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
Then in your code set it up as:
public class WebActivity extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webcontent);
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://websitesby.projectcaruso.com/");
}
}