Comments (6)
Thanks!
Although it’s more of a question for their repository vs. this one here, you got everything right already.
If the following is all they did to integrate this library here, it’s not enough, because they missed all custom callbacks and listeners:
jasonelle-archive/jasonette-android@08488dd
The method you have identified should be the critical one, others might be necessary for other features.
I think it should fit in app/src/main/java/com/jasonette/seed/Core/JasonViewActivity.java
, on the same level as void onBackPressed()
.
Does that help?
from android-advancedwebview.
Thank you for your reply. I tried to implement this one by adding:
--- JasonViewActivity.java.ORIG 2021-08-26 13:15:55.599885405 +0200
+++ JasonViewActivity.java 2021-08-26 13:17:13.246513986 +0200
@@ -157,6 +157,19 @@
}
}
+ @Override
+ public void onDownloadRequested(String url, String suggestedFilename, String mimeType, long contentLength, String contentDisposition, String userAgent) {
+ // some file is available for download
+ // either handle the download yourself or use the code below
+
+ if (AdvancedWebView.handleDownload(this, url, suggestedFilename)) {
+ // download successfully handled
+ }
+ else {
+ // download couldn't be handled because user has disabled download manager app on the device
+ // TODO show some notice to the user
+ }
+ }
@Override
protected void onCreate(Bundle savedInstanceState) {
but building in Android Studio says
method does not override or implement a method from a supertype :160
160 is the @OverRide
from android-advancedwebview.
Addition: I read somewhere that somtes removing @OverRide helps. Triesd it, then it compiles, but then the download is not working as without the addition.
from android-advancedwebview.
I’m sorry, there are more missing pieces. You can add back the @Override
. It helps. If it does not compile, the error is somewhere else:
First, you must change
public class JasonViewActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback{
to
public class JasonViewActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback, AdvancedWebView.Listener {
Then, after
backgroundWebview = agentService.setup(JasonViewActivity.this, background, "$webcontainer@" + model.url);
you have to insert the line
((AdvancedWebView) backgroundWebview).setListener(JasonViewActivity.this, JasonViewActivity.this);
And finally, you may have to add more methods from the README, as you did with that one method, until it stops complaining that some methods are not implemented.
from android-advancedwebview.
SOLVED
Thank you so much for your help! It works perfect now! For all running into the same problem:
- Checkout advanced-webview branch of Jasonette
- Patch like this one:
@@ -1,5 +1,10 @@
+// patches as mentioned in
+// https://github.com/delight-im/Android-AdvancedWebView/issues/299
+// with the great help of ocram. THANK YOU SO MUCH!
+// this handles now also in-app downloads using advanced web view
+
package com.jasonette.seed.Core;
import android.app.SearchManager;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -82,11 +87,13 @@ import java.util.concurrent.Executors;
import static com.bumptech.glide.Glide.with;
import im.delight.android.webview.AdvancedWebView;
-public class JasonViewActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback{
+// changed for downloads
+//public class JasonViewActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback{
+public class JasonViewActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback, AdvancedWebView.Listener {
private JasonToolbar toolbar;
private RecyclerView listView;
public String url;
public JasonModel model;
public JSONObject preload;
@@ -155,10 +162,39 @@ public class JasonViewActivity extends AppCompatActivity implements ActivityComp
}else{
super.onBackPressed();
}
}
+ // Handle Downloads
+
+ @Override
+ public void onDownloadRequested(String url, String suggestedFilename, String mimeType, long contentLength, String contentDisposition, String userAgent) {
+ // some file is available for download
+ // either handle the download yourself or use the code below
+
+ if (AdvancedWebView.handleDownload(this, url, suggestedFilename)) {
+ // download successfully handled
+ }
+ else {
+ // download couldn't be handled because user has disabled download manager app on the device
+ // TODO show some notice to the user
+ }
+ }
+
+ @Override
+ public void onExternalPageRequest(String url) { }
+
+ @Override
+ public void onPageStarted(String url, Bitmap favicon) { }
+
+ @Override
+ public void onPageFinished(String url) { }
+
+ @Override
+ public void onPageError(int errorCode, String description, String failingUrl) { }
+
+ // END Downloads
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -1950,10 +1986,13 @@ public class JasonViewActivity extends AppCompatActivity implements ActivityComp
// therefore, unlike ios where each viewcontroller owns a web container through "$webcontainer" id,
// on android we need to distinguish between multiple web containers through URL
background.put("id", "$webcontainer@" + model.url);
JasonAgentService agentService = (JasonAgentService)((Launcher)getApplicationContext()).services.get("JasonAgentService");
backgroundWebview = agentService.setup(JasonViewActivity.this, background, "$webcontainer@" + model.url);
+ //Added for Downloads
+ ((AdvancedWebView) backgroundWebview).setListener(JasonViewActivity.this, JasonViewActivity.this);
+ // END
backgroundWebview.setVisibility(View.VISIBLE);
// do not apply any zoom on the text.
backgroundWebview.getSettings().setTextZoom(100);
// not interactive by default;
from android-advancedwebview.
Glad to hear that it works, thank you!
The only thing you don’t have yet is a status message informing the user about the result of their download.
To implement that, around the call to AdvancedWebView.handleDownload
, just place a one-liner displaying a Toast or Snackbar in both the if
and the else
branch.
from android-advancedwebview.
Related Issues (20)
- JavaScript Interface don't work HOT 2
- (Fullscreen) videos not working HOT 1
- Loading iframe inside webpage
- Is the XSS vulnerability fixed here? HOT 3
- Migrate to mavenCentral HOT 1
- Unable to view PDF From Amazon Service Url in AdvanceWebview. HOT 2
- Update AdvancedWebView and increase performance HOT 1
- Allow fullscreen mode ? HOT 1
- There is no loadHtml() command.
- Support to open google maps link with the google maps app HOT 1
- Datatables export buttons not working.
- Cannot cast my MainActivity into Advanced Webview Listener HOT 2
- Hide header and footer HOT 1
- Camera and audio permission issue
- Unresolved reference: im HOT 1
- Ask for photo on picture upload
- ANR HOT 1
- im.delight.android.webview.AdvancedWebView, was not found in the project or the libraries HOT 1
- How to disable webview navigate to another page?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-advancedwebview.