Asked  2 Years ago    Answers:  5   Viewed   41 times

In an iOS app, I used

stringFromJavaScript = [webView stringByEvaluatingJavascriptFromString:@"document.getElementById("image").getAttribute("src")"];

To get the src directory of the image that was being displayed on the webView. I want to do the same for Android. What are my options?

Basically the intent is to capture the path so that I can email this same picture...

ie.

"picture.php?image=%@",stringFromJavascript

This way, that same image would be loaded when the user clicks the link, or posts it to facebook etc.

 Answers

5

Yeah, I miss this method greatly in Android ;)

To execute JavaScript and get response you can do as follows:

  1. Define JavaScript callback interface in your code:

    class MyJavaScriptInterface {
        @JavascriptInterface
        public void someCallback(String jsResult) {
             // your code...
        }
    }
    
  2. Attach this callback to your WebView

    MyJavaScriptInterface javaInterface = new MyJavaScriptInterface();
    yourWebView.addJavascriptInterface(javaInterface, "HTMLOUT");
    
  3. Run your JavaScript calling window.HTMLOUT.someCallback from the script:

    yourWebView.loadUrl("javascript:( function () { var resultSrc = document.getElementById("image").getAttribute("src"); window.HTMLOUT.someCallback(resultSrc); } ) ()");
    

Hope this helps!

Wednesday, October 5, 2022
5

I see at least two errors on this code:

private static final String REGISTER_REQUEST_URL = "http://localhost/phptesting/Register.php";

Android doesn't like localhost you can read it here.

Best option is to do an ifconfig and get your ip address and instead of localhost put your ip address like

http://192.168.1.158/phptesting/Register.php

Also your localhost should have a port, right? So make sure you add it just in case in your BASE_URL, so it should look like this

http://192.168.1.158:8080/phptestig/Register.php

Then the call should work.

Then I see another problem with

mysqli_stmt_bind_param($statement, "siss",$username,$password,$isAdmin);

You are passing 4 values to an insert that requires 3.

I recommend you to go step by step, first make sure your api call is registering something (you can use PostMan or ARC to do it) and then go to Android side.

Saturday, November 26, 2022
 
chadt
 
1

The equivalent of an Android TextView in iOS is UILabel and UITextView. The one you want for large amounts of text is UITextView. Below are descriptions taken from the documentation:

UITextView

The UITextView class implements the behavior for a scrollable, multiline text region. The class supports the display of text using custom style information and also supports text editing. You typically use a text view to display multiple lines of text, such as when displaying the body of a large text document.

UILabel

The UILabel class implements a read-only text view. You can use this class to draw one or multiple lines of static text, such as those you might use to identify other parts of your user interface.

UITextField

A UITextField object is a control that displays editable text and sends an action message to a target object when the user presses the return button. You typically use this class to gather small amounts of text from the user and perform some immediate action, such as a search operation, based on that text.

Here are some links for further research:

  • Using Text Kit to Draw and Manage Text (documentation)
  • Text Kit Tutorial in Swift
  • Using Text Kit to Manage Text in Your iOS Apps
  • ios: best way to display variable-length, multi-line text
Tuesday, August 9, 2022
 
jermah
 
3

There is nothing wrong with your code. This is a logging message internal to Apple, and you should file a radar about it.

There are two hints that show that this is probably Apple's code:

  1. The underscore leading the method name _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion is a convention indicating that the method is private/internal to the class that it's declared in. (See this comment.)

  2. It's reasonable to guess that the two letter prefix in FBSSceneSnapshotAction is shorthand for FrontBoard, which according to Rene Ritchie in "iOS 9 wish-list: Guest Mode" is part of the whole family of software related to launching apps:

With iOS 8, Apple refactored its system manager, SpringBoard, into several smaller, more focused components. In addition to BackBoard, which was already spun off to handle background tasks, they added Frontboard for foreground tasks. They also added PreBoard to handle the Lock screen under secure, encrypted conditions. [...]

I have no idea what the BS prefix in BSSettings is for, but

BS is shorthand for BackBoard Settings, and an analysis of this log message would indicate that it's not anything you did, and you should file a radar with steps to reproduce the logging message.

If you want to try and grab a stack trace, you can implement the category linked to here. Some would argue that overriding private API is a bad idea, but in this case a temporary injection to grab a stack trace can't be too harmful.

EDIT:

But, we still want to know what this action is. So I put a breakpoint on -[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion] and started printing out register values and found a class called FBSceneImpl which had a whole bunch of information about my application:

We are able to find out which private method is called next (stored in the program counter, instruction pointer, register 15.)

I tried finding the un-handled FBSceneSnapshotAction referenced in the log, but no dice. Then, I subclassed UIApplication, and overrode _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion. Now I was able to get at the action directly, but still, we don't know what it is.

Then, I looked at the FBSceneSnapshotAction again. Turns out it has a superclass called BSAction.

Then I wrote a tool similar to RuntimeBrowser and looked up all of the subclasses of BSAction. It turns out that there's quite a list of them:

The two method names we have (one from the log and one from the program counter on the devices) indicate that these actions are used under the hood for passing actions around the system.

Some actions are probably sent up to the app delegate's callbacks, while others are handled internally.

What's happening here is that there is an action that wasn't handled correctly and the system is noting it. We weren't supposed to see it, apparently.

Friday, August 19, 2022
 
3

in your:

private void sendGps(final Double lat, final Double lon, final String name) 

method, you don't send the params (lat lon name) to your PHP backend. I'm not so familiar with PHP, but I suppose, as this params are not included on your POST, php uses default values: "" for String and 0 for Numbers.

to send data you need to change your Request from StringRequest to JsonObjectRequest

so your code look something like this:

HashMap<String, String> params = new HashMap<String, String>();
params.put("lat", ""+lat);
params.put("lon", ""+lon);
params.put("name", name);

JsonObjectRequest strReq = new JsonObjectRequest(
          AppConfig.URL_GPS, new JSONObject(params), new Response.Listener<String>() {

be aware you need to change your response listener, because you get a json object response now.

Sunday, August 28, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 

Browse Other Code Languages