Advanced Android Development

stickscarpenterMobile - Wireless

Jul 19, 2012 (5 years and 1 month ago)

288 views

Advanced Android Development
郭惠翔
hhkuo@nccu.edu.tw
BEFORE DEVELOPMENT
Three Websites You MUST Know
Please download
http://140.119.164.2/MapDemo.zip
If you didn’t attend last Friday
• Android Developers
–http://developer.android.com
• Android Open Source Project
–http://developer.android.com
• Google
–http://www.google.com.tw
GOOGLE MAP
How to use Google Map in Your Application
1st
• Execute DOS and get MD5
• keytool –list –keystore “keystore path”
2nd
• http://code.google.com/android/maps-api-signup.html
• Enter MD5
3rd
• Use the Maps API key in your MapActivity or MapView
Window → Preference →
Android → Build → Default
debug keystore
6
th
. Run as Android Application
Congrats!!
LOCATION POSITIONING
GPS & Network
Techniques
My
Location
NETWORK
Mobile
Network
WI-FI
GPS
Let’s Start !!
1
st
. Add Uses-Permission
Open AndroidManifest.xml
Choose Tag「Permissions」
Click 「Add」and Choose
「Uses permission」
android.permission.ACCESS
_FINE_LOCATION
2
nd
. Implement LocationListener
• public class MapDemo extends MapActivity
implements LocationListener

{

blah blah blah blah blah blah blah
• }
3
rd
. Add Unimplemented Methods
• boolean isRouteDisplayed()
• void onLocationChanged(Location)
• void onProviderDisabled(String)
• void onProviderEnabled(String)
• void onStatusChanged(String, int, Bundle)
4
th
. Initiate LocationManager

private void updateLocation() {
LocationManager mgr = (LocationManager)
getSystemService(LOCATION_SERVICE);
mgr.requestLocationUpdates(LocationMan
ager.GPS_PROVIDER, 0, 0, this);
• }
5
th
. Obtain Geographical Location
• void onLocationChanged(Location location)

{
GeoPoint gp = new GeoPoint((int)
(location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
mc.animateTo(gp);
• }
6
th
. Call updateLocation() in onCreate()
7
th
. Run as Android Application
8
th
.
Use DDMS to Send GPS Location Data
「Window」→「Open Perspective」
→「DDMS」
Congrats!!
INTENT-FILTERS
Android Apps Are Created Equal
Have You Noticed …
• <intent-filter . . . >
<action android:name="code android.intent.action.MAIN" />
<category android:name="code android.intent.category.LAUNCHER" />
• </intent-filter>
To be delivered to the component that
owns the filter, it must pass all three
tests.
Action Test, Category Test, and Data Test.
1
st
. Action Test
<intent-filter . . . >
<action android:name="com.example.project.SHOW_CURRENT" />
<action android:name="com.example.project.SHOW_RECENT" />
<action android:name="com.example.project.SHOW_PENDING" />
</intent-filter>
2
nd
. Category Test
<intent-filter . . . >
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
3
rd
. Data Test
<intent-filter . . . >
<data android:mimeType="video/mpeg“ />
<data android:mimeType="audio/mpeg“ />
<data android:mimeType="text/plain" />
<data android:mimeType="image/*" />
</intent-filter>
Example : Replace Home Screen
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Example : Share Your Photo
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
zzzz…
LIVE WALLPAPER
Richer, Animated, Interactive Backgrounds
Please Download
http://140.119.164.2/LiveWallpaperDemo.zip
A live wallpaper is very similar to a
regular Android service.
Difference
@Override
public Engine onCreateEngine()
{
return new CubeEngine();
}
1
st
. Create Wallpaper Project
2
nd
. Create a WallpaperService.Engine

class CubeEngine extends Engine{
– void onSurfaceCreated
– void onSurfaceChanged
– void onVisibilityChanged

void onOffsetsChanged
• }
3
rd
. AndroidManifest.xml
<uses-sdk android:minSdkVersion="7" />
<uses-feature
android:name="android.software.live_wallpaper" />
3
rd
. AndroidManifest.xml (Cont.)
<service
android:label="@string/wallpaper_cube1"
android:name=".cube1.CubeWallpaper1"
android:permission="android.permission.BIND_WALLPAPER">
<intent-filter>
<actionandroid:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data android:name="android.service.wallpaper"
android:resource="@xml/cube1" />
</service>
APP WIDGET
Supported Layout Supported Widget
FrameLayout AnalogClock
LinearLayout Chronometer
RelativeLayout Button
ImageButton
ImageView
ProgressBar
TextView
「Dev Guide」→「Framework Topics」→「App Widgets」
For More Information, Please Visit
http://developer.android.com
Thanks for your attendance!!