Best android questions in October 2010

Android Emulator Tips and Tricks

25 votes

What is your Emulator feature that you could not work without?

Which unknown great shortcut, console command or startup option is there that you discovered and you think has to be also known by all other Android devs?

Share your Emulator wisdom with us.

F6 - start track ball emulation

When working with high resolution screen, one can reduce the size of the emulator to make it fit better on PC screen: AVD Manager - Start - check "Scale display to real size" and set Screen size to a suitable value (6 works for me)

Can you programmatically detect white noise?

22 votes

The Dell Streak has been discovered to have an FM radio which has very crude controls. 'Scanning' is unavailable by default, so my question is does anyone know how, using Java on Android, one might 'listen' to the FM radio as we iterate up through the frequency range detecting white noise (or a good signal) so as to act much like a normal radio's seek function?

I have done some practical work on this specific area, i would recommend (if you have a little time for it) to try just a little experimentation before resorting to fft'ing. The pcm stream can be interpreted very complexely and subtly (as per high quality filtering and resampling) but can also be practically treated for many purposes as the path of a wiggly line.

White noise is unpredictable shaking of the line, which is never-the-less quite continuous in intensity (rms, absolute mean..) Acoustic content is recurrent wiggling and occasional surprises (jumps, leaps) :]

Non-noise like content of a signal may be estimated by performing quick calculations on a running window of the pcm stream.

For example, noise will strongly tend to have a higher value for the absolute integral of its derivative, than non-noise. I think that is the academic way of saying this:

loop(n+1 to n.length)
{ sumd0+= abs(pcm[n]); 
  sumd1+= abs(pcm[n]-pcm[n-1]); 
}

wNoiseRatio = ?0.8; //quite easily discovered, bit tricky to calculate.

if((sumd1/sumd0)<wNoiseRatio)
{ /*not like noise*/ }

Also, the running absolute average over ~16 to ~30 samples of white noise will tend to vary less, over white noise than acoustic signal:

loop(n+24 to n.length-16)
{ runAbsAve1 += abs(pcm[n]) - abs(pcm[n-24]); }

loop(n+24+16 to n.length)
{ runAbsAve2 += abs(pcm[n]) - abs(pcm[n-24]); }

unusualDif= 5; //a factor. tighter values for longer measures.

if(abs(runAbsAve1-runAbsAve2)>(runAbsAve1+runAbsAve2)/(2*unusualDif))
{ /*not like noise*/ }

This concerns how white noise tends to be non-sporadic over large enough span to average out its entropy. Acoustic content is sporadic (localised power) and recurrent (repetitive power). The simple test reacts to acoustic content with lower frequencies and could be drowned out by high frequency content. There are simple to apply lowpass filters which could help (and no doubt other adaptions).

Also, the root mean square can be divided by the mean absolute sum providing another ratio which should be particular to white noise, though i cant figure what it is right now. The ratio will also differ for the signals derivatives as well.

I think of these as being simple formulaic signatures of noise. I'm sure there are more.. Sorry to not be more specific, it is fuzzy and imprecise advice, but so is performing simple tests on the output of an fft. For better explaination and more ideas perhaps check out statistical and stochastic(?) measurements of entropy and randomness on wikipedia etc.

Android adb "Unable to open sync connection!"

22 votes

I can run and debug my Android app on my phone just fine, most of the time. Then, seemingly randomly, when I try to run or debug my app from Eclipse, the Console in Eclipse says:

[2010-10-12 09:36:48 - myapp] Android Launch!
[2010-10-12 09:36:48 - myapp] adb is running normally.
[2010-10-12 09:36:48 - myapp] Performing com.mycompany.myapp.MyActivity activity launch
[2010-10-12 09:36:48 - myapp] Automatic Target Mode: using device 'HT01TP800561'
[2010-10-12 09:36:48 - myapp] Uploading myapp.apk onto device 'HT01TP800561'
[2010-10-12 09:36:48 - myapp] Failed to upload myapp.apk on device 'HT01TP800561'
[2010-10-12 09:36:48 - myapp] java.io.IOException: Unable to open sync connection!
[2010-10-12 09:36:48 - myapp] Launch canceled!
  • Retry: doesn't help, same messages.
  • Restart Eclipse: doesn't help.
  • Restart adb (adb killserver && adb start-server): no errors, doesn't help.
  • Reconnect the phone: sometimes helps.
  • Reboot the computer: kind of drastic, haven't tried this yet.

Using Ubuntu 10.4, Eclipse Galileo 3.5.2, Android SDK 7, ADT plugin 0.9.6, Nexus One, Android 2.2.1.

Any bright ideas?

I was having exactly the same problem, but I already had my phone connected to the computer's USB port. Sometimes disconnecting and reconnecting the cord worked but then it stopped working completely. However, disabling USB debugging on the phone and then re-enabling it has worked so far. Hopefully it keeps working! These fixes really seem like silly hacks.. I'm not sure what the underlying problem is.

How to Animate Addition or Removal of Android ListView Rows

21 votes

In iOS, there is a very easy and powerful facility to animate the addition and removal of UITableView rows, here's a clip from a youtube video showing the default animation. Note how the surrounding rows collapse onto the deleted row. This animation helps users keep track of what changed in a list and where in the list they were looking at when the data changed.

Since I've been developing on Android I've found no equivalent facility to animate individual rows in a TableView. Calling notifyDataSetChanged() on my Adapter causes the ListView to immediately update its content with new information. I'd like to show a simple animation of a new row pushing in or sliding out when the data changes, but I can't find any documented way to do this. It looks like LayoutAnimationController might hold a key to getting this to work, but when I set a LayoutAnimationController on my ListView (similar to ApiDemo's LayoutAnimation2) and remove elements from my adapter after the list has displayed, the elements disappear immediately instead of getting animated out.

I've also tried things like the following to animate an individual item when it is removed:

@Override
protected void onListItemClick(ListView l, View v, final int position, long id) {
    Animation animation = new ScaleAnimation(1, 1, 1, 0);
    animation.setDuration(100);
    getListView().getChildAt(position).startAnimation(animation);
    l.postDelayed(new Runnable() {
        public void run() {
            mStringList.remove(position);
            mAdapter.notifyDataSetChanged();
        }
    }, 100);
}

However, the rows surrounding the animated row don't move position until they jump to their new positions when notifyDataSetChanged() is called. It appears ListView doesn't update its layout once its elements have been placed.

While writing my own implementation/fork of ListView has crossed my mind, this seems like something that shouldn't be so difficult.

Thanks!

Since Android is open source, you don't actually need to reimplement ListView's optimizations. You can grab ListView's code and try to find a way to hack in the animation, you can also open a feature request in android bug tracker (and if you decided to implement it, don't forget to contribute a patch).

FYI, the ListView source code is here: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/widget/ListView.java;h=892c44af7ffc4605004971b2d6dce88c065f1c76;hb=HEAD

OpenGL ES 2.0 Extensions on Android Devices

16 votes

As this page for OpenGL ES 1.x, i collect OpenGL ES 2.x Extensions for Android Devices on this page. The list can be found with my benchmark tool gpubench. These informations can help many game developpers.

Thanks for your help,

Nexus One (CyanogenMod 6)

SDK:Android 2.2
ID:FRF91
OS name:Linux
OS version:2.6.34.5-cyanogenmod
Vendor:Qualcomm
Driver:OpenGL ES 2.0 1044053
Render:Adreno

GL_OES_compressed_ETC1_RGB8_texture
GL_OES_depth_texture
GL_OES_depth24
GL_OES_EGL_image
GL_OES_element_index_uint
GL_OES_fbo_render_mipmap
GL_OES_fragment_precision_high
GL_OES_get_program_binary
GL_OES_packed_depth_stencil
GL_OES_rgb8_rgba8
GL_OES_standard_derivatives
GL_OES_texture_3D
GL_OES_texture_float
GL_OES_texture_half_float
GL_OES_texture_half_float_linear
GL_OES_texture_npot
GL_OES_vertex_half_float
GL_OES_vertex_type_10_10_10_2
GL_AMD_compressed_3DC_texture
GL_AMD_compressed_ATC_texture
GL_AMD_performance_monitor
GL_AMD_program_binary_Z400
GL_EXT_texture_filter_anisotropic
GL_EXT_texture_format_BGRA8888
GL_EXT_texture_type_2_10_10_10_REV
GL_NV_fence
GL_QCOM_driver_control
GL_QCOM_perfmon_global_mode
GL_QCOM_extended_get
GL_QCOM_extended_get2
GL_QCOM_tiled_rendering
GL_QCOM_writeonly_rendering
GL_QCOM_memory_monitor

Eclipse Android SDK slow Content Assist performance

14 votes

Im running eclipse on my windows 7 machine, 6bit with 6gb ram and core 2 duo. Im currently running Eclipse 3.6 and android 2.2 SDK Im running jdk 1.6

Im noticing that when coding and the context popups to list methods of a class, it hangs Eclipse for up to 15 seconds. This is very frustrating.

One thing to note, when Eclipse hangs, my processor is maxed out, and is being worked by a java process. So its doing something whatever it is. But frequently everytime I finish an object with a period and the context box pops up, its becoming too painful to work with.

I changed some settings in the Eclipse.ini file such as: -Xms1024m -Xmx1024m --launcher.XXMaxPermSize 512m

Is there anything else I should look at:

After a google search

I have been able to find the bug report from Eclipse.

In short:

Caution: There are known issues with the ADT plugin running with Eclipse 3.6. Please stay on 3.5 until further notice.

  • To fix it, you will have to use Eclipse 3.5 and put your project in a newly created workspace. (If you keep the workspace from Eclipse 3.6, the problem will occur even on Eclipse 3.5.)

What happens if the minSdkVersion is lower than the targetSdkVersion?

13 votes

I am getting the warning:

Attribute minSdkVersion (3) is lower than the project target API level (8)

How will this affect my app?

You can safely ignore the warning.

It's a weird warning - it means you are using tools for API level 8 (Android 2.2/Froyo) but targeting API level 3 (Android 1.5/Cupcake). That warning will always come up unless you you were using the SDK to target the Android release it coincides with - in this case, you would have to target Android 2.2 with your current SDK.

Google's voice search speech recognition service

12 votes

Google has speech recognition services available for use from mobile phones (Android has it built in, iPhone users can use the Google application) - http://www.google.com/mobile/. We've found one article where someone tried to reverse engineer the service at http://waxy.org/2008/11/deconstructing_google_mobiles_voice_search_on_the_iphone/.

We want to better understand what is happening over the network when we use Android's RecognizerIntent. Does anyone have any experience using this service over the web or know of other articles that may explain its workings?

I read this presentation few weeks ago- http://www.abelski.com/courses/android/speechinput.pdf

The following link is a 3 mile high review of the Google Voice Server .... http://www.google.co.jp/events/developerday/2010/tokyo/pdf/tt1-gruenstein.pdf

Extending Android's Voice Search app

9 votes

Is it possible to extend the Voice Search app? I know I can add a button in my own app to launch the voice recognition dialog, but I was wondering if I could extend the voice search app that launches automatically when you long press the physical "search" key.

send text to [contact] [message]
listen to [artist/song/album]
call [business]
call [contact]
send email to [contact] [message]
go to [website]
note to self [note]
navigate to [location/business name]
directions to [location/business name]
map of [location]

I'd basically like to add my own action to the above list.

Is this possible or will I have to create my own?

In a word, no. The app doesn't have the extension points you are looking for. You would have to write your own app entirely, which is something that others have done.

How do I add custom data and fields to the the Contacts screen in Android?

8 votes

I'm trying to add a custom data field and MIME type to the Contacts screen. Is there a way to do this such that when a user views a contact with my data saved on it, my field appears there? This is something I've seen other apps do--how do the Facebook, Twitter, Last.fm, etc. apps add their status information to contacts, for example? I can't seem to figure it out from the Contacts API documentation.

This guide gives a very good description on how to do what you asked: http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1

Is using scala on android worth it? Is there a lot of overhead? Problems?

8 votes

I was thinking of building an app on android with Scala instead of the regular Java (or the equivalent I guess). Is it worth it? Any problems and unnecessary headaches?

Working with Scala should be mostly painless, as the dex compiler just works with bytecode - which is exactly what Scala produces.

Your biggest problem then is the dependency on scala-library, as dex expects everything to be in a single Jar. This is best handled with Proguard (which will also remove unused code and give you a smaller executable, ideal for mobile)


Current best practice is to use SBT with the Android plugin; It'll take care of everything for you: http://github.com/jberkel/android-plugin

If you must use Eclipse and the plugin supplied by Google, then you're going to have a non-standard directory structure. I also wrote an article on how to deal with this: http://www.assembla.com/wiki/show/scala-ide/Developing_for_Android

But be warned... it takes a lot more effort that way!

Augmented Reality Toolkit - Android

8 votes

I have been searching around for free or commercial AR toolkits and need some advice on the best one!

I don't want to have one that recognises a pattern and creates a shape. The idea I have uses the local location and uses POI's from a server to present them onto an AR view.

Any ideas?

As you don't want one which recognizes shapes, writing one is fairly trivial. You need to detect the user's location, the camera orientation and then draw stuff on the camera. I made one for an app recently and it works quite well. Followed this tutorial: http://www.devx.com/wireless/Article/42482

The guy also has written an AR kit. http://twitter.com/#!/androidarkit, http://code.google.com/p/androidarkit/