In it's latest 4.2 version, Android developers introduced a new featured called DayDream which is basically an interactive screensaver. As you may already guess, this features activates when the phone is in the idle state but it also activates when the phone is charging.
The developers have the possibility of creating custom "dreams" (screensavers) by extending the DreamService class. This class provides several methods which can be overridden to implement custom functionality.
These are quite simple to understand. The onAttachedToWindow() serves as a typical init method, where you can initialize various stuff for you "dream". However, you must'n start any animation now. You can do this by overriding the onDreamingStarted() method.
The other methods you can override are onDreamingStopped() and onDetachedFromWindow() which are the "end" versions of the first two.
DreamService also has a method called setInteractive which let's you specify wheter your "dream" is an interactive one or not. A "dream" is interactive if it's not interrupted by the user's touch.
You can write a simple static "dream" by creating a new Activity layout and then calling setContentView(R.layout.yourdreamlayoutid) inside the onAttachedToWindow method described above.
For more documentation, check the official documentation.
Adroid 4.2 - new API explained and sample applications
Tuesday, 27 November 2012
Less accurate ACCESS_COARSE_LOCATION
According to the official specification, Android 4.2 returns less exact coordinates in case of determining the user's location using ACCESS_COARSE_LOCATION permission.
As you may already know, to be able to determine the user's location the application must request the ACCESS_COARSE_LOCATION permission OR the ACCESS_FINE_LOCATION, the later returning more precise results (also, may be using more battery power as it queries the integrated GPS chip).
The ACCESS_COARSE_LOCATION permission still works, don't worry, but results returned by it may not be as accurate as those returned by previous Android versions.
So.. if in the past your application worked just fine by using just ACCESS_COARSE_LOCATION permission, you may need to test it again and switch to ACCESS_FINE_LOCATION if the new results do not satisfy the needs of your application.
As you may already know, to be able to determine the user's location the application must request the ACCESS_COARSE_LOCATION permission OR the ACCESS_FINE_LOCATION, the later returning more precise results (also, may be using more battery power as it queries the integrated GPS chip).
The ACCESS_COARSE_LOCATION permission still works, don't worry, but results returned by it may not be as accurate as those returned by previous Android versions.
So.. if in the past your application worked just fine by using just ACCESS_COARSE_LOCATION permission, you may need to test it again and switch to ACCESS_FINE_LOCATION if the new results do not satisfy the needs of your application.
The new UserHandle class
Android 4.2 API (level 17) introduced several new classes, providing programatic support for different new features that were introduced. The UserHandle is a new class that basically represents a user on the device.
Full specifications for this class can be found on the official Android Developer website.
This class implements the good old Parcelable interface and exposes a new static method called writeToParcel that you can use to write a specific user (represented by UserHandle) to a Parcel object.
Full specifications for this class can be found on the official Android Developer website.
This class implements the good old Parcelable interface and exposes a new static method called writeToParcel that you can use to write a specific user (represented by UserHandle) to a Parcel object.
The new UserManager class
Android API 17 (introduced in Android 4.2) introduces a new class responsible with managing users in a multi-user environment. As I said before, the multi-user feature is only enabled in tablets.
The official documentation for this class is avaible here.
So what's this all about? This class exposes 7 methods that give you some information about the users currently operating the tablet.
The most straight-forward one is getUserCount() which, pretty obviously, returns the number of user accounts created on the tablet.
The getUserName() function returns the name of the user that is currently logged on. This is useful for generating personalised content (such as displaying the user's name in the corner of your app - or anything you can think of).
The isUserAGoat() function is actually an easter egg and I also made a separate post about it.
The official documentation for this class is avaible here.
So what's this all about? This class exposes 7 methods that give you some information about the users currently operating the tablet.
The most straight-forward one is getUserCount() which, pretty obviously, returns the number of user accounts created on the tablet.
The getUserName() function returns the name of the user that is currently logged on. This is useful for generating personalised content (such as displaying the user's name in the corner of your app - or anything you can think of).
The isUserAGoat() function is actually an easter egg and I also made a separate post about it.
Monday, 26 November 2012
isUserAGoat method
I myself was surprised to find this method in the Android API 17. This is a method that is part of the UserManager class which is a brand-new class introduced in this API release.
Of course, after I saw the method I did some research on the Android developer page, searching for other mentions of this 'goat' term. Of course, I didn't, but I found another interesting method in a much older class.
In the ActivityManager class there is a method called isUserAMonkey which, as the official documentation states, "Returns "true" if the user interface is currently being messed with by a monkey. ".
It seemes that Google programmers decided to give us developers a new easter egg, this time using goats as a practical joke.
To be sure, I took a sneak peek inside the source code, to be sure that the isUserAGoat method is just an easter egg.
As you can see in this screenshot of the UserManager.java class source code, the implementation of the method is actually just a plain return false statement.
As this may seem funny at least for most people, I know some programming goats who won't be that happy they are being left out of the Android platform.
Of course, after I saw the method I did some research on the Android developer page, searching for other mentions of this 'goat' term. Of course, I didn't, but I found another interesting method in a much older class.
In the ActivityManager class there is a method called isUserAMonkey which, as the official documentation states, "Returns "true" if the user interface is currently being messed with by a monkey. ".
It seemes that Google programmers decided to give us developers a new easter egg, this time using goats as a practical joke.
To be sure, I took a sneak peek inside the source code, to be sure that the isUserAGoat method is just an easter egg.
As you can see in this screenshot of the UserManager.java class source code, the implementation of the method is actually just a plain return false statement.
As this may seem funny at least for most people, I know some programming goats who won't be that happy they are being left out of the Android platform.
Android 4.2 is here!
On 13 November 2012 Google launched the newest version of it's popular Android operating system for smartphones.
This version comes with new features, like multiple user accounts (supported only on tablets), support for wireless display or increased number of extended notifications and Actionable Notifications. A complete list of the features it introduces can be found at the Android official website or on the Android version history page on Wikipedia.
Of course, there are some new API classes that support these features. This website is not about just posting some Android application code online! I will try to explain to you how these new API's work and provide you some sample applications that can really help you developing yours.
Stay tuned!
This version comes with new features, like multiple user accounts (supported only on tablets), support for wireless display or increased number of extended notifications and Actionable Notifications. A complete list of the features it introduces can be found at the Android official website or on the Android version history page on Wikipedia.
Of course, there are some new API classes that support these features. This website is not about just posting some Android application code online! I will try to explain to you how these new API's work and provide you some sample applications that can really help you developing yours.
Stay tuned!
Subscribe to:
Comments (Atom)
