如何在android中实现调用键盘事件监听

2023-12-07

我想实施我的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>**

我是这样解决这个问题的:

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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在android中实现调用键盘事件监听 的相关文章