【问题标题】:how to implement calling keypad event listener in android如何在android中实现调用键盘事件监听器
【发布时间】:2012-03-13 05:34:57
【问题描述】:

我想在按下某个组合键时实现我的BroadcastReceiver (比如说如果我从我的键盘拨 1234)他们我的BroadcastReceiver 将被呼叫。我可以通过哪些方式启动我的活动?

这是我解决这个问题的方法

这是我解决这个问题的方法

public class MyKeypadListener extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub



     if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {

         String number = getResultData();   
         if (number!=null) {

            if(number.equals("1234")){

                 setResultData(null);
                 Intent newintent = new Intent(context,SettingsActivity.class);
                 newintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                 context.startActivity(newintent);
                       }

             }


          }
        }

}

我在清单中添加了..

**<receiver android:name=".receivers.MyKeypadListener">
            <intent-filter >
                    <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
                   <action android:name="android.intent.action.PHONE_STATE"/>
            </intent-filter>
        </receiver>**

【问题讨论】:

  • 嗨@Rashmi,我们可以只使用组合键来触发活动,而不是拨打组合键吗?
  • 您想要哪种类型的组合键.. 目前我正在谈论 android 呼叫键盘..

标签: android android-intent listener


【解决方案1】:

这是我解决这个问题的方法:

public class MyKeypadListener extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub



 if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {

     String number = getResultData();   
     if (number!=null) {

        if(number.equals("1234")){

             setResultData(null);
             Intent newintent = new Intent(context,SettingsActivity.class);
             newintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
             context.startActivity(newintent);
                   }

         }


      }
        }

}

在清单中我添加了:

<receiver android:name=".receivers.MyKeypadListener">
            <intent-filter >
                    <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
                   <action android:name="android.intent.action.PHONE_STATE"/>
            </intent-filter>
        </receiver>

【讨论】:

    【解决方案2】:

    您必须在输入这些组合的编辑文本中实现TextWatcher。此 API 有一些回调方法,您可以在其中轻松检查您的组合。

    【讨论】:

    • 没有我必须实现的编辑文本。它只是标准的安卓拨号盘,我通过它来监控输入的 ksy 组合。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-25
    • 2018-04-15
    • 2015-08-14
    • 1970-01-01
    相关资源
    最近更新 更多