We've got application to view some specific materials. Among material types there is HTML5 presentation that is shown in WebView widget inside app. And now we need to get detailed information about this view (for example slide show duration, list element pick where it is available, etc).
It is what customer wants - we can't change it.
We decided to use IndexedDB inside HTML5 to store information locally. Now storing works (as I know :) ). Next problem is to get this information by app and it is not solved yet. Unfortunately google didn't help me.
How to get information from IndexedDB file if I know its path? Or do you know another way to transfer data from html to native app?
P.S. Writing custom browser could not be solution.
Update
Found solution to load file from JS. In chrome browser it automatically saves in downloads. In android app I'm setting to WebView object DownloadListener to listen file save event.
Catching save file works perfect. But the url path is looks like blob:file/... and I can't get info from it. Tried using ContentResolver, create File object, replace blob: string with nothing, start ACTION_VIEW intent - nothing helped.
Update
Tried to use DownloadManager and DownloadManager.Request - it throws following exception
java.lang.IllegalArgumentException: Can only download HTTP/HTTPS URIs: file:///fa4857ad-0e86-454a-a341-123729e9ece0
Same with blob:file uri.
Is it a requirement to use IndexedDB for communication?
If not, you could add a javascript interface. Simply pass on the data as JSON string and then decode it on the java side.
https://developer.android.com/guide/webapps/webview.html#BindingJavaScript
Mind security (don't allow the user to browse to different pages, sanitize incoming data, ...) ;-)
You can solve the problem by hack by calling the JavaScript function from Java and returning the required attributes in specific pattern. To implement this
Create the javascript function which will return the attributes in
specific pattern.
Create the WebChromClient and override onJsAlert() method. message
parameter of onJsAlert has the returned string of message. Parse the
message string to get the required attributes.
Call the JavaScript function from Java code to get the value.
final class MyWebChromeClient extends WebChromeClient {
#Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
result.confirm();
// Parse the message to get the required attributes
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
return true;
}
}
To call the JavaScript function to get the data use the below code. Here testFunction() is the fucntion which will return the data in string format.
webView.loadUrl("javascript:alert(testFunction())");
Create the instance of WebChromeClient and set in webview and also don't forget to enable the JavaScript.
WebView webView = (WebView)findViewById(R.id.web_view);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new MyWebChromeClient());
We decided to use ServerSocket for localhost as web server on device. And then Html sends to it http responce. May be using java script binding as wrote #Michael2 whould be better, but our solution was realized before his post. :-)
Related
I am trying to make a web browser with javafx, but I need to get the url of the website that the user is on. I tryed using getDocument(), but that didn't work, and there's no getUrl() method. Will you tell me how I can accomplish this.
Just to add onto Zephyr's answer I would like to give you the code you need:
browserName.getEngine().load("https://www." + urlFieldName.getText());
urlFieldName.setText(browserName.getEngine().getLocation());
I have integrated the GWT application with Chrome packaged app with help of DirectLinkerinstaller like the code below:
public class CSPCompatibleLinker extends DirectInstallLinker {
#Override
protected String getJsInstallLocation(LinkerContext context) {
return "com/google/gwt/core/ext/linker/impl/installLocationMainWindow.js";
}
}
But now I want to call print function from Chrome packaged app. When I call window.print() it allows me to print current window, but I need to open a new separate window and print that.
Could you anyone please help me in this?
I can't answer anything about GWT or DirectLinkerinstaller, but here's an answer about Chrome Apps, assuming that's what you're asking about:
You use the chrome.app.window.create API to create a window. Then, you can call the print method for that window.
In my apps, I seldom want to print what's in a window, but rather something I've generated specifically for printing. For that, I create a PDF with jsPDF (Google it), which works well. Then I display the PDF in a window, and let the user print the PDF (or save it).
I need some advice for this matter...
I used the facebook android sdk to create an integration with facebook from my application...I followed this tutorial:
http://www.integratingstuff.com/2010/10/14/integrating-facebook-into-an-android-application/
I would need to implement authentication in one activity and the function postToWall in another.... after authentication i want to send post simply by pressing a button but in other activity, different from that where i do authentication.
is it possible? or with the SDK I'm forced to do everything together in the same activity?
thanks in advance
Yes it is possible. You will get a access token which you can send to the next activity. Use getAccessToken() and setAccessToken().
Here is an example that even saves the needed data: Contact-Picture-Sync
you need to install an extension, similar to the core Android SDK, but no, here is what you need to do:
1.) go to github.com/facebook/facebook-android-sdk
2.) download the facebook directory ONLY! The other directories are only examples.
3.) Put the files from the src (you can copy the drawables too, if you want to) in the package, you are currently working with
4.) You are good to go, you can use the facebook "SDK"
see also this example https://github.com/facebook/facebook-android-sdk/tree/master/examples/Hackbook download it , it is working example provided by facebook
just to provide an alternative answer, there's other ways of implementing sharing on Android.
It allows for more sharing options (like Twitter, QR-Barcodes, blogging and whatnot) without having to deal with the facebook android sdk.
What you would use is a "share" intent, like so:
String title = "My thing"; // used if you share through email or channels that require a headline for the content, always include this or some apps might not parse the content right
String wallPost = "Hey - check out this stuff: http://link.com "; // the content of your wallpost
String shareVia = "Share this stuff via"; // the headline for your chooser, where the phones avaliable sharing mechanisms are offered.
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, title);
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, wallPost);
startActivity(Intent.createChooser(shareIntent, shareVia));
This is by far the preferred solution on Android if you're looking for simple sharing, as it makes your app future-compatible with new services. And more lean and flexible for the user too, as there's little to no friction from hitting the share button to posting content.
It can also be seen in this blog post: http://android-developers.blogspot.com/2012/02/share-with-intents.html
I hope you can use this for your project.
I am developing an application in blackberry.The application has got list field items.So when i click any list-field item,it should open the default email client of the device,so that the person can share that item.Can anyone provide sample code for sharing item via email in blackberry?
It's pretty easy, actually. Call the Invoke.invokeApplication method, as shown in this example:
http://docs.blackberry.com/en/developers/deliverables/11935/Invoke_BB_device_software_app_565421_11.jsp
You can use this to make phone calls, open the calendar, etc.
I've been looking into the Android SDK's example of the SearchableDictionary for a while now, but I'm still not sure if that is the right approach.
The problem is, that I want to fill my hint list (see picture below) with data, which I will receive via a HTTP/JSON query. So I'm not sure if using a ContentProvider as used in the above example is the right thing to do. Can I access the hint list of the SearchBox in some way more direct?
You can overload the onSearchRequested for the searchmanager and return a custom data set the the given query. make sure to use an asyncTask if you are connecting to the web for your data to avoid ANR's
#Override
public boolean onSearchRequested() {
Bundle appData = new Bundle();
appData.put...();
...
startSearch(null, false, appData);
return true;
}