【问题标题】:Adding IR remote control to android application in android 4.4在 android 4.4 中将 IR 遥控器添加到 android 应用程序
【发布时间】:2015-01-03 19:57:42
【问题描述】:

我希望我的应用程序由红外遥控器控制。并且应用程序必须在 kitkat 版本中运行。基本上在这里我有 4 个图像视图,我希望用户使用 IR 遥控器移动和选择特定图像。谁能帮我从哪里开始?我应该只坚持一个特定的遥控器,还是所有遥控器上的遥控器都一样。

【问题讨论】:

    标签: android android-4.4-kitkat remote-control infrared


    【解决方案1】:

    终于找到解决办法了!!!! :) 下面是示例代码。

        public class DpadActivity extends Activity {
    
    private ImageView iv1,iv2;
    private static Toast tst;
    private int current_position=1;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dpad);
        iv1=(ImageView)findViewById(R.id.imageView1);
        iv2=(ImageView)findViewById(R.id.ImageView2);
    
        iv1.requestFocus();
        iv1.setBackgroundResource(R.drawable.hilight);
    
    
        iv2.setOnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(), "iv2 clicked", Toast.LENGTH_LONG).show();
            }
        });
    
    
        iv1.setOnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(), "iv1 clicked", Toast.LENGTH_LONG).show();
            }
        });
    
    
    
    tst.makeText(getApplicationContext(), "Ha hai", Toast.LENGTH_LONG).show();
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    
        if (KeyEvent.KEYCODE_DPAD_CENTER == keyCode
                || KeyEvent.KEYCODE_ENTER == keyCode) {
    tst.makeText(getApplicationContext(), "Enter Pressed", Toast.LENGTH_LONG).show();
            return true;
        } else if (KeyEvent.KEYCODE_DPAD_LEFT == keyCode) {
    tst.makeText(getApplicationContext(), "Left Pressed", Toast.LENGTH_LONG).show();
            return true;
        } else if (KeyEvent.KEYCODE_DPAD_RIGHT == keyCode) {
            tst.makeText(getApplicationContext(), "Right Pressed", Toast.LENGTH_LONG).show();
            return true;
        } else if (KeyEvent.KEYCODE_DPAD_UP == keyCode) {
            if(current_position==1)
            {
                iv2.requestFocus();
                current_position=2;
            }else if(current_position==2)
            {
                iv1.requestFocus();
                current_position=1;
            }
            tst.makeText(getApplicationContext(), "Up Pressed", Toast.LENGTH_LONG).show();
            return true;
        } else if (KeyEvent.KEYCODE_DPAD_DOWN == keyCode) {
            if(current_position==1)
            {
                iv2.requestFocus();
                current_position=2;
            }else if(current_position==2)
            {
                iv1.requestFocus();
                current_position=1;
            }
            tst.makeText(getApplicationContext(), "Down Pressed", Toast.LENGTH_LONG).show();
            return true;
    
        }
    
        Toast.makeText(getApplicationContext(), "Nothing Detected", Toast.LENGTH_LONG).show();
        return super.onKeyDown(keyCode, event);
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多