Android Programming Tutorials

(Romina) #1
Raising (Something Like) a Tweet

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="apt.tutorial.two"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="@string/app_name">
<activity android:name=".Patchy"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

If you recompile and reinstall the application, you should now be able to


update your identi.ca status by filling in the fields and clicking the Send


button.


You will notice that we are making this HTTP request on the main


application thread. That is not a good practice – it can freeze the user


interface, and if the request takes too long, Android will display the


dreaded "application not responding" dialog box. However, we will address


that problem in the next tutorial (or in an Extra Credit item, if you prefer).


If you work in a facility that requires a proxy server, your emulator may be


unhappy (as might Android devices operating on WiFi behind the proxy).


You may need to add the following snippet of code to work past that,


adjusting the parameters to suit your office's setup:


Properties systemSettings=System.getProperties();

systemSettings.put("http.proxyHost", "your.proxy.host.here");
systemSettings.put("http.proxyPort", "8080"); // use actual proxy port

Extra Credit................................................................................................


Here are some things you can try beyond those step-by-step instructions:



  • Process the post request in a background thread and display a Toast
    when the request is complete and successful.


162
Free download pdf