Add Voice Typing To Your IME

December 13th, 2011 by Android Dev

[This post is by Luca Zanolin, an Android engineer who works on voice typing. — Tim Bray]

A new feature available in Android 4.0 is voice typing: the difference for users is that the recognition results appear in the text box while they are still speaking. If you are an IME developer, you can easily integrate with voice typing.

To simplify the integration, if you download this library and modify your IME as described below, everything will work smoothly on any device with Android 2.2 or later. On 4.0+, users will get voice typing, and earlier versions will use standard voice recognition; the difference is illustrated below.

To see how to integrate voice typing you can take a look at this sample IME. The IME is really simple and contains only one button: a microphone. By pressing the microphone, the user triggers voice recognition.

Here are the steps that you need to follow to integrate voice recognition into your IME.

Download the library

Download this library and add it to your IME APK.

Create the voice recognition trigger

The library contains the VoiceRecognitionTrigger helper class. Create an instance of it inside the InputMethodService#onCreate method in your IME.

public void onCreate() {
    super.onCreate();
    ...
    mVoiceRecognitionTrigger = new VoiceRecognitionTrigger(this);
}

Add the microphone icon to your IME

You need to modify the UI of your IME, add a microphone icon, and register an OnClickListener to trigger voice recognition. You can find the assets inside the sample IME. The microphone icon should be displayed only if voice recognition is installed; use VoiceRecognitionTrigger#isInstalled().

public View onCreateInputView() {
  LayoutInflater inflater = (LayoutInflater) getSystemService(
      Service.LAYOUT_INFLATER_SERVICE);
  mView = inflater.inflate(R.layout.ime, null);
  ...
  mButton = (ImageButton) mView.findViewById(R.id.mic_button);
  if (mVoiceRecognitionTrigger.isInstalled()) {
    mButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        mVoiceRecognitionTrigger.startVoiceRecognition();
      }
    });
    mButton.setVisibility(View.VISIBLE);
  } else {
    mButton.setVisibility(View.GONE);
  }
  return mView;
}

If your IME supports multiple languages, you can specify in which language recognition should be done as a parameter of startVoiceRecognition().

Notify the trigger when your IME starts

When your IME starts, you need to notify the trigger, so it can insert into the text view any pending recognition results.

@Override
public void onStartInputView(EditorInfo info, boolean restarting) {
  super.onStartInputView(info, restarting);
  if (mVoiceRecognitionTrigger != null) {
    mVoiceRecognitionTrigger.onStartInputView();
  }
}

Modify your AndroidManifest

In order to start a voice recognition through the Intent API, the library uses a service and an activity, and you need to add them into your manifest.

<manifest ... >
  <application ...>
    ...
    <service android:name="com.google.android.voiceime.ServiceHelper" />
    <activity
        android:name="com.google.android.voiceime.ActivityHelper"
        android:theme="@android:style/Theme.Translucent.NoTitleBar"
        android:excludeFromRecents="true"
        android:windowSoftInputMode="stateAlwaysHidden"
        android:finishOnTaskLaunch="true"
        android:configChanges="keyboard|keyboardHidden|navigation
                               |orientation"/>
  </application>
</manifest>

Update the microphone icon dynamically (optional)

This step is optional, but you should implement it if possible as it will improve the user experience. Voice recognition requires network access, and if there is no network, your IME should notify the user that voice recognition is currently disabled. To achieve this, you need to register the VoiceRecognitionTrigger.Listener and enable/disable the microphone accordingly.

The listener is registered in InputMethodService#onCreate, and you have to unregister it in InputMethodService#onDestroy, otherwise you will leak the listener.

@Override
public void onCreate() {
  super.onCreate();
  ...
  mVoiceRecognitionTrigger = new VoiceRecognitionTrigger(this);
  mVoiceRecognitionTrigger.register(new VoiceRecognitionTrigger.Listener() {
    @Override
    public void onVoiceImeEnabledStatusChange() {
      updateVoiceImeStatus();
    }
  });
}

...
@Override
public void onDestroy() {
  ...
  if (mVoiceRecognitionTrigger != null) {
    mVoiceRecognitionTrigger.unregister(this);
  }
  super.onDestroy();
}

private void updateVoiceImeStatus() {
  if (mVoiceRecognitionTrigger.isInstalled()) {
    mButton.setVisibility(View.VISIBLE);
    if (mVoiceRecognitionTrigger.isEnabled()) {
      mButton.setEnabled(true);
    } else {
      mButton.setEnabled(false);
    }
  } else {
    mButton.setVisibility(View.GONE);
  }
  mView.invalidate();
}

And add this permission into your manifest:

<manifest ... >
  ...
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  ...
</manifest>

That’s all there is to it

Voice recognition makes it easy for users to do more with their Android devices, so we appreciate your support in adding it to your IMEs.

Coby to Reveal Five New Ice Cream Sandwich Tablets at CES

December 13th, 2011 by Android Dev

This image has no alt text

Personal electronics manufacturer Coby have announced that they will have a big showing at CES. We’re set to get five different Ice Cream Sandwich tablets in the 7-10 inch range. A 1GHz ARM Cortex A8 processor sit inside these devices, an unusual choice for Android tablets these days. The only Cortex A8-based processors we’ve seen inside Honeycomb-capable models are the 1.5GHz Snapdragon processors inside HTC Flyer and its variants. It’ll be interesting to see what processor choice Coby has gone with and how Ice Cream Sandwich will perform on it. The tablets will also have 1GB of RAM inside but no other information is know at this time. [via]


Swarm LLC releases free social SDK for Android developers

December 13th, 2011 by Android Dev

swarmSwarm LLC has just released a social SDK for Android developers, with tools like leaderboards, achievements, and even cloud storage.

read more

Verizon’s Claims That Google Wallet Leaves Concern for Information Security May Have Legs

December 13th, 2011 by Android Dev

This image has no alt text

A good chunk of the smartphone world – Verizon’s Android customers in particular – were in uproar regarding news that their version of the Galaxy Nexus would not be coming with Google Wallet.

We speculated (and still do believe) that their mobile payments partners in ISIS were the leading reason why they were reluctant to provide the service. After all, Sprint is still the only carrier to offer it and they only offer it on one device – the Nexus S 4G.

But they officially cited that Google Wallet was left out due to concerns about security and user experience. The last bit of that – UX – is so broad a term that one could come up with any estimation as to what they mean, but security? Well, that’s a legitimate concern.

Verizon elected not to go into grave detail regarding their security concerns at the time of their statement but we may have a vague look at what’s going on via viaForensics. What they reportedly found is just a bit alarming, if true:

  • Google Wallet does securely handle full credit card information
  • Certain database writes are unencrypted and can contain troubling information, such as account balances, credit limits, last four digits of a credit card and the expiration date – all pieces of information that can easily be used to social engineer one’s way into fraud.
  • This information is only at risk on rooted devices. Still, not good.

There were other security concerns but they have apparently been cleaned up in software upgrades. We assume the issues listed above won’t go long without Google’s attention though there’s no word on what they’ll be doing about it and when.

We’re not sure if this is the type of stuff holding Verizon or any carriers other than Sprint from offering Google Wallet but we can understand why they wouldn’t be comfortable with it.

That’s not to say we know for sure whether or not Verizon will offer this service whenever their concerns are addressed, but we’d at least know there’s a chance. And yes, we’re hoping these findings won’t delay the Galaxy Nexus even further. Just offer Google Wallet in the market and call it a day. [via TheVerge]


Custom control states in library projects

December 13th, 2011 by Android Dev

SDK Version: 

M3

RELEASE TO PUBLIC

This is a tutorial about adding states to custom controls in library projects. So first, how to create and reference library projects: Setting up library projects, Referencing library projects.

Now that the project is setup you can start creating custom controls and states for them. This will all be inside the library project. Firstly you need to create an attributes xml file in values/attrs.xml (the name has to be attrs.xml) and adding the state:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>    
  3.     <declare-styleable name="customTextViewState&quot;>
  4.         <attr name="state_marked" format="boolean" />
  5.     </declare-styleable>    
  6. </resources>

read more