How to enable YouTube video download in Web view in Android studio?
I added Youtube web view to new activity in my Android app with Android Studio.My phone default Youtube app can download videos like below image.So Can I enable that download facility to my web view in Android Studio ?
Please help me to solve this issue.
Here is my web view
public class BeanVideos extends AppCompatActivity {
WebView mWebView;
ProgressBar progressBar;
TextView textView;
LinearLayout liProgressContainer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_beanvideos);
textView = (TextView) findViewById(R.id.tvLoadingPercentage);
liProgressContainer = (LinearLayout) findViewById(R.id.liProgressContainer);
progressBar = (ProgressBar) findViewById(R.id.progressbar);
mWebView = (WebView) findViewById(R.id.webView);
progressBar.setVisibility(View.VISIBLE);
mWebView.setWebViewClient(new Browser_home());
mWebView.setWebChromeClient(new MyChrome());
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowFileAccess(true);
webSettings.setAppCacheEnabled(true);
loadWebsite();
}
private void loadWebsite() {
ConnectivityManager cm = (ConnectivityManager) getApplication().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) { mWebView.loadUrl("https://www.youtube.com/channel/UC4UaWbUUUNqhb4GdsKLS6Q/videos");
} else {
mWebView.setVisibility(View.GONE);
}
}
//back button function
@Override
public void onBackPressed() {
if (mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
class Browser_home extends WebViewClient {
Browser_home() {
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
liProgressContainer.setVisibility(View.VISIBLE);
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
progressBar.setVisibility(View.GONE);
super.onPageFinished(view, url);
liProgressContainer.setVisibility(View.GONE);
}
}
private class MyChrome extends WebChromeClient {
private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
protected FrameLayout mFullscreenContainer;
private int mOriginalOrientation;
private int mOriginalSystemUiVisibility;
public void onProgressChanged(WebView view, int progress) {
progressBar.setProgress(progress);
textView.setText(progress + " %");
}
MyChrome() {}
public Bitmap getDefaultVideoPoster()
{
if (mCustomView == null) {
return null;
}
return BitmapFactory.decodeResource(getApplicationContext().getResources(), 2130837573);
}
public void onHideCustomView()
{
((FrameLayout)getWindow().getDecorView()).removeView(this.mCustomView);
this.mCustomView = null;
getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
setRequestedOrientation(this.mOriginalOrientation);
this.mCustomViewCallback.onCustomViewHidden();
this.mCustomViewCallback = null;
}
public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback)
{
if (this.mCustomView != null)
{
onHideCustomView();
return;
}
this.mCustomView = paramView;
this.mOriginalSystemUiVisibility = getWindow().getDecorView().getSystemUiVisibility();
this.mOriginalOrientation = getRequestedOrientation();
this.mCustomViewCallback = paramCustomViewCallback;
((FrameLayout)getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1));
getWindow().getDecorView().setSystemUiVisibility(3846);
}
}
}
java android-studio webview youtube
add a comment |
I added Youtube web view to new activity in my Android app with Android Studio.My phone default Youtube app can download videos like below image.So Can I enable that download facility to my web view in Android Studio ?
Please help me to solve this issue.
Here is my web view
public class BeanVideos extends AppCompatActivity {
WebView mWebView;
ProgressBar progressBar;
TextView textView;
LinearLayout liProgressContainer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_beanvideos);
textView = (TextView) findViewById(R.id.tvLoadingPercentage);
liProgressContainer = (LinearLayout) findViewById(R.id.liProgressContainer);
progressBar = (ProgressBar) findViewById(R.id.progressbar);
mWebView = (WebView) findViewById(R.id.webView);
progressBar.setVisibility(View.VISIBLE);
mWebView.setWebViewClient(new Browser_home());
mWebView.setWebChromeClient(new MyChrome());
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowFileAccess(true);
webSettings.setAppCacheEnabled(true);
loadWebsite();
}
private void loadWebsite() {
ConnectivityManager cm = (ConnectivityManager) getApplication().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) { mWebView.loadUrl("https://www.youtube.com/channel/UC4UaWbUUUNqhb4GdsKLS6Q/videos");
} else {
mWebView.setVisibility(View.GONE);
}
}
//back button function
@Override
public void onBackPressed() {
if (mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
class Browser_home extends WebViewClient {
Browser_home() {
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
liProgressContainer.setVisibility(View.VISIBLE);
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
progressBar.setVisibility(View.GONE);
super.onPageFinished(view, url);
liProgressContainer.setVisibility(View.GONE);
}
}
private class MyChrome extends WebChromeClient {
private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
protected FrameLayout mFullscreenContainer;
private int mOriginalOrientation;
private int mOriginalSystemUiVisibility;
public void onProgressChanged(WebView view, int progress) {
progressBar.setProgress(progress);
textView.setText(progress + " %");
}
MyChrome() {}
public Bitmap getDefaultVideoPoster()
{
if (mCustomView == null) {
return null;
}
return BitmapFactory.decodeResource(getApplicationContext().getResources(), 2130837573);
}
public void onHideCustomView()
{
((FrameLayout)getWindow().getDecorView()).removeView(this.mCustomView);
this.mCustomView = null;
getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
setRequestedOrientation(this.mOriginalOrientation);
this.mCustomViewCallback.onCustomViewHidden();
this.mCustomViewCallback = null;
}
public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback)
{
if (this.mCustomView != null)
{
onHideCustomView();
return;
}
this.mCustomView = paramView;
this.mOriginalSystemUiVisibility = getWindow().getDecorView().getSystemUiVisibility();
this.mOriginalOrientation = getRequestedOrientation();
this.mCustomViewCallback = paramCustomViewCallback;
((FrameLayout)getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1));
getWindow().getDecorView().setSystemUiVisibility(3846);
}
}
}
java android-studio webview youtube
1
Not sure it's still valid since Youtube premium is out but it may be a duplicate of stackoverflow.com/questions/39933132/…
– jhamon
Jan 3 at 15:12
add a comment |
I added Youtube web view to new activity in my Android app with Android Studio.My phone default Youtube app can download videos like below image.So Can I enable that download facility to my web view in Android Studio ?
Please help me to solve this issue.
Here is my web view
public class BeanVideos extends AppCompatActivity {
WebView mWebView;
ProgressBar progressBar;
TextView textView;
LinearLayout liProgressContainer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_beanvideos);
textView = (TextView) findViewById(R.id.tvLoadingPercentage);
liProgressContainer = (LinearLayout) findViewById(R.id.liProgressContainer);
progressBar = (ProgressBar) findViewById(R.id.progressbar);
mWebView = (WebView) findViewById(R.id.webView);
progressBar.setVisibility(View.VISIBLE);
mWebView.setWebViewClient(new Browser_home());
mWebView.setWebChromeClient(new MyChrome());
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowFileAccess(true);
webSettings.setAppCacheEnabled(true);
loadWebsite();
}
private void loadWebsite() {
ConnectivityManager cm = (ConnectivityManager) getApplication().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) { mWebView.loadUrl("https://www.youtube.com/channel/UC4UaWbUUUNqhb4GdsKLS6Q/videos");
} else {
mWebView.setVisibility(View.GONE);
}
}
//back button function
@Override
public void onBackPressed() {
if (mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
class Browser_home extends WebViewClient {
Browser_home() {
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
liProgressContainer.setVisibility(View.VISIBLE);
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
progressBar.setVisibility(View.GONE);
super.onPageFinished(view, url);
liProgressContainer.setVisibility(View.GONE);
}
}
private class MyChrome extends WebChromeClient {
private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
protected FrameLayout mFullscreenContainer;
private int mOriginalOrientation;
private int mOriginalSystemUiVisibility;
public void onProgressChanged(WebView view, int progress) {
progressBar.setProgress(progress);
textView.setText(progress + " %");
}
MyChrome() {}
public Bitmap getDefaultVideoPoster()
{
if (mCustomView == null) {
return null;
}
return BitmapFactory.decodeResource(getApplicationContext().getResources(), 2130837573);
}
public void onHideCustomView()
{
((FrameLayout)getWindow().getDecorView()).removeView(this.mCustomView);
this.mCustomView = null;
getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
setRequestedOrientation(this.mOriginalOrientation);
this.mCustomViewCallback.onCustomViewHidden();
this.mCustomViewCallback = null;
}
public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback)
{
if (this.mCustomView != null)
{
onHideCustomView();
return;
}
this.mCustomView = paramView;
this.mOriginalSystemUiVisibility = getWindow().getDecorView().getSystemUiVisibility();
this.mOriginalOrientation = getRequestedOrientation();
this.mCustomViewCallback = paramCustomViewCallback;
((FrameLayout)getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1));
getWindow().getDecorView().setSystemUiVisibility(3846);
}
}
}
java android-studio webview youtube
I added Youtube web view to new activity in my Android app with Android Studio.My phone default Youtube app can download videos like below image.So Can I enable that download facility to my web view in Android Studio ?
Please help me to solve this issue.
Here is my web view
public class BeanVideos extends AppCompatActivity {
WebView mWebView;
ProgressBar progressBar;
TextView textView;
LinearLayout liProgressContainer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_beanvideos);
textView = (TextView) findViewById(R.id.tvLoadingPercentage);
liProgressContainer = (LinearLayout) findViewById(R.id.liProgressContainer);
progressBar = (ProgressBar) findViewById(R.id.progressbar);
mWebView = (WebView) findViewById(R.id.webView);
progressBar.setVisibility(View.VISIBLE);
mWebView.setWebViewClient(new Browser_home());
mWebView.setWebChromeClient(new MyChrome());
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowFileAccess(true);
webSettings.setAppCacheEnabled(true);
loadWebsite();
}
private void loadWebsite() {
ConnectivityManager cm = (ConnectivityManager) getApplication().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) { mWebView.loadUrl("https://www.youtube.com/channel/UC4UaWbUUUNqhb4GdsKLS6Q/videos");
} else {
mWebView.setVisibility(View.GONE);
}
}
//back button function
@Override
public void onBackPressed() {
if (mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
class Browser_home extends WebViewClient {
Browser_home() {
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
liProgressContainer.setVisibility(View.VISIBLE);
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
progressBar.setVisibility(View.GONE);
super.onPageFinished(view, url);
liProgressContainer.setVisibility(View.GONE);
}
}
private class MyChrome extends WebChromeClient {
private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
protected FrameLayout mFullscreenContainer;
private int mOriginalOrientation;
private int mOriginalSystemUiVisibility;
public void onProgressChanged(WebView view, int progress) {
progressBar.setProgress(progress);
textView.setText(progress + " %");
}
MyChrome() {}
public Bitmap getDefaultVideoPoster()
{
if (mCustomView == null) {
return null;
}
return BitmapFactory.decodeResource(getApplicationContext().getResources(), 2130837573);
}
public void onHideCustomView()
{
((FrameLayout)getWindow().getDecorView()).removeView(this.mCustomView);
this.mCustomView = null;
getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
setRequestedOrientation(this.mOriginalOrientation);
this.mCustomViewCallback.onCustomViewHidden();
this.mCustomViewCallback = null;
}
public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback)
{
if (this.mCustomView != null)
{
onHideCustomView();
return;
}
this.mCustomView = paramView;
this.mOriginalSystemUiVisibility = getWindow().getDecorView().getSystemUiVisibility();
this.mOriginalOrientation = getRequestedOrientation();
this.mCustomViewCallback = paramCustomViewCallback;
((FrameLayout)getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1));
getWindow().getDecorView().setSystemUiVisibility(3846);
}
}
}
java android-studio webview youtube
java android-studio webview youtube
edited Jan 3 at 15:07
jhamon
2,22331830
2,22331830
asked Jan 3 at 15:04
Mr.SoftMr.Soft
488
488
1
Not sure it's still valid since Youtube premium is out but it may be a duplicate of stackoverflow.com/questions/39933132/…
– jhamon
Jan 3 at 15:12
add a comment |
1
Not sure it's still valid since Youtube premium is out but it may be a duplicate of stackoverflow.com/questions/39933132/…
– jhamon
Jan 3 at 15:12
1
1
Not sure it's still valid since Youtube premium is out but it may be a duplicate of stackoverflow.com/questions/39933132/…
– jhamon
Jan 3 at 15:12
Not sure it's still valid since Youtube premium is out but it may be a duplicate of stackoverflow.com/questions/39933132/…
– jhamon
Jan 3 at 15:12
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54024866%2fhow-to-enable-youtube-video-download-in-web-view-in-android-studio%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54024866%2fhow-to-enable-youtube-video-download-in-web-view-in-android-studio%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Not sure it's still valid since Youtube premium is out but it may be a duplicate of stackoverflow.com/questions/39933132/…
– jhamon
Jan 3 at 15:12