CS185c
Chris Pollett
Oct. 12, 2009
<uses-permission android:name="android.permission.INTERNET"></uses-permission>to the manifest file
<WebView android:id="@+id/webview" android:layout_width="fill_parent" android:layout_height="wrap_content" />
webview = (WebView) findViewById(R.id.webview); webview.getSettings().setJavaScriptEnabled(true); webview.loadUrl("http://www.pollett.org/");
private class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }
webview.setWebViewClient(new MyWebViewClient());
URL/service_name/method_name/?arg1=value1&arg2=value2...which requests from the given URL the given method of the given web service with the given arguments.
String location="URL/service_name/method_name/?arg1=value1&arg2=value2"; String result = null; try { url = new URL(location); } catch (MalformedURLException e) { //handle somehow } if(url != null) { try { HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); BufferedReader in = new BufferedReader( new InputStreamReader( urlConn.getInputStream())); String inputLine; while((inputLine = in.readLine()) != null) { result += "\n" + inputLine; } } catch (IOException e) { // handle somehow } return result; } return null;
Which of the following statements is true:
- (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after application launch [window makeKeyAndVisible]; CGRect bounds = [[UIScreen mainScreen ] applicationFrame]; UIWebView *webView = [[UIWebView alloc] initWithFrame:bounds]; webView.scalesPageToFit = YES; [window addSubview:webView]; NSURL *url = [NSURL URLWithString:@"http://www.pollett.org"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [webView loadRequest:request]; }
webView.delegate = myDelegate;
NSData *myData = [NSData dataWithContentsOfURL: [NSURL URLWithString: @"http://web_service_url"]];
UIImage *image = [UIImage imageWithData: myData];
NSString *string = [NSString stringWithFormat:@"%.*s", [myData length], [myData bytes]];