Thursday, July 29, 2010

Re: [android-developers] Receiving System Intents with Custom Broadcast Receiver

That broadcast tells you when the current input method component has changed (that is the user has switched from one input method to another).

Interaction with the current input method is done through the view APIs.  For the case of the IME being shown, you find out about this indirectly through your view hierarchy being resized to accommodate it.  There is no direct "IME is shown" state.

On Fri, Jul 16, 2010 at 12:37 PM, Evan Cummings <emcummings@gmail.com> wrote:
Hello All,

I am attempting to listen for system fired Intents, specifically
regarding text input, using a class extending BroadcastReceiver. I see
there is an Intent called ACTION_INPUT_METHOD_CHANGED
(android.intent.action.INPUT_METHOD_CHANGED) which I hope to be able
to use to know when the keyboard or text input is attempted by the
user. (I assume this intent will work as I can use an
InputMethodManager object to handle keyboard related tasks)

My java code:

package com.BroadcastReception;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;


public class InputMethodChangedReceiver extends BroadcastReceiver {

       @Override
       public void onReceive(Context arg0, Intent arg1) {
               // TODO Auto-generated method stub
               if
(arg1.getAction().equals("android.intent.action.INPUT_METHOD_CHANGED"))
{
                       Log.d(this.toString(), "Event Fired");
               }
       }
}


My Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.BroadcastReception"
     android:versionCode="1"
     android:versionName="1.0">
   <application android:icon="@drawable/icon" android:label="@string/
app_name">
               <receiver android:name=".InputMethodChangedReceiver"
android:enabled="true">
                       <intent-filter>
                               <action
android:name="android.intent.action.INPUT_METHOD_CHANGED"></
action>
                       </intent-filter>
               </receiver>

   </application>

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

</manifest>

Using DDMS I never see my logs written, indicating to me that my
broadcast receiver is not functioning properly.

My question is this:

1) Is INPUT_METHOD_CHANGED the correct intent to receive on to
determine if the user is attempting to use the keyboard, and if not,
what would be the proper method to use to monitor to see if the user
opens up the keyboard, and

2) Am I doing something incorrect in listening for the event,
permissions, filters, etc? It would seem to me based on the resources
I've looked at it that I'm along the right track, but I must be
missing something!

I appreciate the help and responses

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en



--
Dianne Hackborn
Android framework engineer
hackbod@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment