本文主要是介绍RK3588 遥控器按键长按 0、1、2、3 键跳转指定 APP,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
diff --git a/RK3588_Source/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java b/RK3588_Source/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
index b090d47679f…6805d065ad6 100755
— a/RK3588_Source/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/RK3588_Source/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -733,6 +733,23 @@ public class PhoneWindowManager implements WindowManagerPolicy {case MSG_RINGER_TOGGLE_CHORD:handleRingerChordGesture();break;
+ //cczheng add for KEYCODE_0 KEYCODE_1 KEYCODE_2 KEYCODE_3 longpress
+ case MSG_KEY0_LONG_PRESS:
+ mKey0Handled = true;
+ customKeyLongPress(pkgName0);
+ break;
+ case MSG_KEY1_LONG_PRESS:
+ mKey1Handled = true;
+ customKeyLongPress(pkgName1);
+ break;
+ case MSG_KEY2_LONG_PRESS:
+ mKey2Handled = true;
+ customKeyLongPress(pkgName2);
+ break;
+ case MSG_KEY3_LONG_PRESS:
+ mKey3Handled = true;
+ customKeyLongPress(pkgName3);
+ break;//end}}}@@ -3508,6 +3545,102 @@ public class PhoneWindowManager implements WindowManagerPolicy {}}+ //cczheng add for KEYCODE_0 KEYCODE_1 KEYCODE_2 KEYCODE_3 longpress
+ private static final int MSG_KEY0_LONG_PRESS = 133;
+ private static final int MSG_KEY1_LONG_PRESS = 130;
+ private static final int MSG_KEY2_LONG_PRESS = 131;
+ private static final int MSG_KEY3_LONG_PRESS = 132;
+
+ private final String pkgName0 = "com.android.tv.settings";
+ private final String pkgName1 = "com.liskovsoft.smarttubetv.beta";
+ private final String pkgName2 = "org.xbmc.kodi";
+ private final String pkgName3 = "com.ss.android.ugc.trill";
+ volatile boolean mKey0Handled;
+ volatile boolean mKey1Handled;
+ volatile boolean mKey2Handled;
+ volatile boolean mKey3Handled;
+
+ private void handleKey0Button(KeyEvent event) {
+ final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
+ if (down) {
+ Message msg = mHandler.obtainMessage(MSG_KEY0_LONG_PRESS);
+ msg.setAsynchronous(true);
+ mHandler.sendMessageDelayed(msg, 3000);
+ mKey0Handled = false;
+ Log.d(TAG, "handleKey0Button delayed=");
+ }else{
+ if (!mKey0Handled) {
+ mKey0Handled = true;
+ mHandler.removeMessages(MSG_KEY0_LONG_PRESS);
+ Log.i(TAG, "handleKey0Button removeMessages=");
+ }
+ }
+ }
+
+ private void handleKey1Button(KeyEvent event) {
+ final int repeatCount = event.getRepeatCount();
+ final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
+ final boolean canceled = event.isCanceled();
+ Log.d(TAG, "repeatCount="+repeatCount+" canceled="+canceled+" down="+down);
+ if (down) {
+ Message msg = mHandler.obtainMessage(MSG_KEY1_LONG_PRESS);
+ msg.setAsynchronous(true);
+ mHandler.sendMessageDelayed(msg, 3000);
+ mKey1Handled = false;
+ }else{
+ if (!mKey1Handled) {
+ mKey1Handled = true;
+ mHandler.removeMessages(MSG_KEY1_LONG_PRESS);
+ }
+ }
+ }
+
+ private void handleKey2Button(KeyEvent event) {
+ final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
+ if (down) {
+ Message msg = mHandler.obtainMessage(MSG_KEY2_LONG_PRESS);
+ msg.setAsynchronous(true);
+ mHandler.sendMessageDelayed(msg, 3000);
+ mKey2Handled = false;
+ }else{
+ if (!mKey2Handled) {
+ mKey2Handled = true;
+ mHandler.removeMessages(MSG_KEY2_LONG_PRESS);
+ }
+ }
+ }
+ private void handleKey3Button(KeyEvent event) {
+ final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
+ if (down) {
+ Message msg = mHandler.obtainMessage(MSG_KEY3_LONG_PRESS);
+ msg.setAsynchronous(true);
+ mHandler.sendMessageDelayed(msg, 3000);
+ mKey3Handled = false;
+ }else{
+ if (!mKey3Handled) {
+ mKey3Handled = true;
+ mHandler.removeMessages(MSG_KEY3_LONG_PRESS);
+ }
+ }
+ }
+
+ private void customKeyLongPress(String pkgName){
+ Intent intent = mContext.getPackageManager().getLaunchIntentForPackage(pkgName);
+ if (intent != null) {
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ try {
+ mContext.startActivity(intent);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ Log.i(TAG, "customKeyLongPress done ....");
+ }//end
+
+
+void initializeHdmiStateInternal() {boolean plugged = false;// watch for HDMI plug messages if the hdmi switch exists
@@ -3588,7 +3721,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {final int displayId = event.getDisplayId();final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;- if (DEBUG_INPUT) {
+ //if (DEBUG_INPUT) {// If screen is off then we treat the case where the keyguard is open but hidden// the same as if it were open and in front.// This will prevent any keys other than the power button from waking the screen
@@ -3599,7 +3732,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {Log.d(TAG, "interceptKeyTq keycode=" + keyCode+ " interactive=" + interactive + " keyguardActive=" + keyguardActive+ " policyFlags=" + Integer.toHexString(policyFlags));
- }
+ //}// Basic policy based on interactive state.int result;
@@ -3700,6 +3833,24 @@ public class PhoneWindowManager implements WindowManagerPolicy {// Handle special keys.switch (keyCode) {
+ //cczheng add for KEYCODE_0 KEYCODE_1 KEYCODE_2 KEYCODE_3 longpress
+ case KeyEvent.KEYCODE_0: {
+ handleKey0Button(event);
+ break;
+ }
+ case KeyEvent.KEYCODE_1: {
+ handleKey1Button(event);
+ break;
+ }
+ case KeyEvent.KEYCODE_2: {
+ handleKey2Button(event);
+ break;
+ }
+ case KeyEvent.KEYCODE_3: {
+ handleKey3Button(event);
+ break;
+ }//end
+case KeyEvent.KEYCODE_BACK: {if (down) {mBackKeyHandled = false;
这篇关于RK3588 遥控器按键长按 0、1、2、3 键跳转指定 APP的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!