Senin, 17 Agustus 2009

Referring to Android Resources Using URIs

In addition to loading Android resources using the Resource manager, you can also reference resources using a specially-formatted URI. Resource URIs can be referenced by resource type/name or by resource identifier. This can be especially useful if you are using a control like a VideoView which takes either a file path or a URI for the video source.

For example, let's say we have a VideoView and we want to load a resource from the raw resources called myvideo.3gp. We could construct a URI in two ways:

Using the resource id, the format is:

"android.resource://[package]/[res id]"

Uri path = Uri.parse("android.resource://com.androidbook.samplevideo/" + R.raw.myvideo);

or, using the resource subdirectory (type) and resource name (filename without extension), the format is:

"android.resource://[package]/[res type]/[res name]"

Uri path = Uri.parse("android.resource://com.androidbook.samplevideo/raw/myvideo");


This Uri can then be used to source the VideoView as follows:

VideoView myVid = (VideoView) findViewById(R.id.VideoView1);
myVid.setVideoURI(path);


You can now refer to any resource by URI.

Jumat, 14 Agustus 2009

Sample Chapter From Our Book Available

Our first book, Android Wireless Application Development, is very close to hitting the shelves. Amazon currently lists August 28th availability. Of course, you can still get the Rough Cuts and check it out early!

A free sample chapter, Introducing Android, is now available on informIT. Check it out and give us feedback!


Kamis, 06 Agustus 2009

Creating an App Widget with Custom Timing

App Widgets are a popular new feature with the Android 1.5 SDK. Writing a basic App Widget would seem straightforward, however some properties turn out to get in the way of simple features.
The Android documentation for App Widgets references the ability to let users choose the duration between updates. In practice, the update duration property of an App Widget is immutable. Our latest article on developer.com addresses this, giving code and instruction on creating an Android App Widget with a user-customizable update duration.
ANDROID BOOK © 2008 Template by:
SkinCorner