1 / 12

CE881: Mobile and Social Application Programming Networking and Social Apps

CE881: Mobile and Social Application Programming Networking and Social Apps. Simon M. Lucas. Overview. Motivation Multi-user apps (one user per device) Social apps Better connected apps Technology Simple sharing with Intents Network Connectivity and WiFi Direct Overview of Facebook API.

erno
Download Presentation

CE881: Mobile and Social Application Programming Networking and Social Apps

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CE881: Mobile and Social Application ProgrammingNetworking and Social Apps Simon M. Lucas

  2. Overview • Motivation • Multi-user apps (one user per device) • Social apps • Better connected apps • Technology • Simple sharing with Intents • Network Connectivity and WiFi Direct • Overview of Facebook API

  3. Simple Sharing with Intents • Can use an Intent.ACTION_SEND to send to a recipient • Recommended way is to use a Chooser dialog with this • However, the effects are a bit random, and work better for some recipients than for others • E.g. The code shown next work fine for email, texting and Bluetooth, but not so well for Facebook • In the case of Facebook, the message body was lost! • Still: a good method when you want to user in the loop

  4. Intent sharing code: Intent.ACTION_SEND(example uses Score class from previous lecture) public void shareHighScore(Score score) { Log.i(TAG, "Trying to share " + score); String message ="CE881, new high score: " + score.person + " : " + score.score; Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, message); sendIntent.setType("text/plain"); startActivity(Intent.createChooser( sendIntent, "Share using?")); }

  5. Internet Connectivity • We’ve already seen some of this • Remember the use of an Intent to pop up a web page? • In that case all the work was done for us by the WebView • We’ll now study an example where the connectivity is managed at a lower level

  6. Example: NetworkUsage.ziphttp://developer.android.com/training/basics/network-ops/connecting.html • Set permissions • Choose HTTP Client • Commonly used for Internet • Could use raw sockets for WiFi direct • Check Network Status • No point proceeding if no network • Perform network operation on separate thread: use an AsyncTask • Connect and download (or upload) data • Do something with the data • In this case: parse XML and reformat as HTML in WebView

  7. Sample AsyncTask // Implementation of AsyncTask used to download XML feed from stackoverflow.com. private class DownloadXmlTask extends AsyncTask<String, Void, String> { protected String doInBackground(String... urls) { try { return loadXmlFromNetwork(urls[0]); } catch (IOException e) { return getResources().getString(R.string.connection_error); } catch (XmlPullParserException e) { return getResources().getString(R.string.xml_error); } } @Override protected void onPostExecute(String result) { setContentView(R.layout.main); // Displays the HTML string in the UI via a WebView WebViewmyWebView = (WebView) findViewById(R.id.webview); myWebView.loadData(result, "text/html", null); } }

  8. WiFi Direct • Can make an Ad Hoc network using Android and other WiFi enabled devices • No need for Internet connectivity • Unfortunately, only available from API Level 16 • Excellent for local multi-user apps • Quizzes • Multi-player games • More details, see here + .zip file: • http://developer.android.com/guide/topics/connectivity/wifip2p.html • Note: the demo app did not fully work for me: • Register and discover worked, but not chat

  9. Facebook SDK for Androidhttp://developers.facebook.com/docs/reference/androidsdk/ • Provides “frictionless” integration of Facebook within your Android app • Study sample apps in Facebook SDK • Enable apps that • Post on your behalf • Arrange games with friends • Check on status of Friends • Import their pictures and other data • Exciting possibilities

  10. Facebook SDK Key Concepts • UiLifecycleHelper • used to help manage lifecycle transitions • Session: • Handle a login to Facebook • Use this to post messages etc • Graph • Access to deep within Facebook • Let’s look at some code … • See Facebook SDK, getting started • http://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/

  11. See Also: Being Good to the Batteryhttp://developer.android.com/training/monitoring-device-state/index.html Monitoring the Battery Level and Charging StateLearn how to alter your app's update rate by determining, and monitoring, the current battery level and changes in charging state. Determining and Monitoring the Docking State and TypeOptimal refresh rates can vary based on how the host device is being used. Learn how to determine, and monitor, the docking state and type of dock being used to affect your app's behavior. Determining and Monitoring the Connectivity StatusWithout Internet connectivity you can't update your app from an online source. Learn how to check the connectivity status to alter your background update rate. You'll also learn to check for Wi-Fi or mobile connectivity before beginning high-bandwidth operations. Manipulating Broadcast Receivers On DemandBroadcast receivers that you've declared in the manifest can be toggled at runtime to disable those that aren't necessary due to the current device state. Learn to improve efficiency by toggling and cascading state change receivers and delay actions until the device is in a specific state.

  12. Summary • Android offers a wide range of connection possibilities • Internet, WiFi, Bluetooth, Nearfield • Some of these are very easy to use • Also third party offerings such as Facebook offer access to sophisticated API • And vast network of social data

More Related