如何实现调用键盘事件监听器在android系统 [英] how to implement calling keypad event listener in android

查看:171
本文介绍了如何实现调用键盘事件监听器在android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现我的广播接收器上pressing一些组合键
(说,如果我从我的键盘拨号1234)他们我的广播接收器将被调用。通过它我可以启动我的活动?

这是我如何解决了这个问题。

这是我如何解决了这个问题。

 公共类MyKeypadListener扩展广播接收器{@覆盖
公共无效的onReceive(上下文的背景下,意图意图){
    // TODO自动生成方法存根     如果(intent.getAction()。等于(Intent.ACTION_NEW_OUTGOING_CALL)){         串号= getResultData();
         如果(数字!= NULL){            如果(number.equals(1234)){                 setResultData(NULL);
                 意图newintent =新意图(背景下,SettingsActivity.class);
                 newintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                 context.startActivity(newintent);
                       }             }
          }
        }}

和在清单中我加入高压..

  ** lt;接收机器人:名字=。receivers.MyKeypadListener>
            &所述;意图滤光器>
                    <作用机器人:名字=android.intent.action.NEW_OUTGOING_CALL/>
                   <作用机器人:名字=android.intent.action.PHONE_STATE/>
            &所述; /意图滤光器>
        < /接收器GT; **


解决方案

下面是我如何解决了这个问题:

 公共类MyKeypadListener扩展广播接收器{@覆盖
公共无效的onReceive(上下文的背景下,意图意图){
    // TODO自动生成方法存根 如果(intent.getAction()。等于(Intent.ACTION_NEW_OUTGOING_CALL)){     串号= getResultData();
     如果(数字!= NULL){        如果(number.equals(1234)){             setResultData(NULL);
             意图newintent =新意图(背景下,SettingsActivity.class);
             newintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
             context.startActivity(newintent);
                   }         }
      }
        }}

和在清单中我已经加入:

 <接收机器人:名字=。receivers.MyKeypadListener>
            &所述;意图滤光器>
                    <作用机器人:名字=android.intent.action.NEW_OUTGOING_CALL/>
                   <作用机器人:名字=android.intent.action.PHONE_STATE/>
            &所述; /意图滤光器>
        < /接收器>

I want to implement my BroadcastReceiver on pressing some key combination (say if i dial 1234 from my keypad) them my BroadcastReceiver will be called. By which i can launch my activity ?

Here is how i fixed this

Here is how i fixed this

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);
                       }

             }


          }
        }

}

and in the manifest i hv added..

**<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>**

解决方案

Here is how I fixed this:

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);
                   }

         }


      }
        }

}

and in the manifest I have added:

<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>

这篇关于如何实现调用键盘事件监听器在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆