mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-10-28 23:09:59 +00:00
Add support for Android 16.1 keyboard capture
Fixes #975 Fixes #1281 Fixes #1505
This commit is contained in:
1 parent
abde6021e8
commit
ddb674a9b9
2 files changed
+31
-23
No files matched your search
@@ -6,6 +6,7 @@
|
|||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.CAPTURE_KEYBOARD" />
|
||||||
<uses-permission android:name="com.android.providers.tv.permission.READ_EPG_DATA"/>
|
<uses-permission android:name="com.android.providers.tv.permission.READ_EPG_DATA"/>
|
||||||
<uses-permission android:name="com.android.providers.tv.permission.WRITE_EPG_DATA"/>
|
<uses-permission android:name="com.android.providers.tv.permission.WRITE_EPG_DATA"/>
|
||||||
|
|
||||||
|
|||||||
@@ -673,31 +673,38 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setMetaKeyCaptureState(boolean enabled) {
|
public void setMetaKeyCaptureState(boolean enabled) {
|
||||||
// This uses custom APIs present on some Samsung devices to allow capture of
|
// Android has native keyboard capture support starting in API 36.1
|
||||||
// meta key events while streaming.
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA && Build.VERSION.SDK_INT_FULL >= Build.VERSION_CODES_FULL.BAKLAVA_1) {
|
||||||
try {
|
WindowManager.LayoutParams windowLayoutParams = getWindow().getAttributes();
|
||||||
Class<?> semWindowManager = Class.forName("com.samsung.android.view.SemWindowManager");
|
windowLayoutParams.setKeyboardCaptureEnabled(enabled);
|
||||||
Method getInstanceMethod = semWindowManager.getMethod("getInstance");
|
getWindow().setAttributes(windowLayoutParams);
|
||||||
Object manager = getInstanceMethod.invoke(null);
|
}
|
||||||
|
else {
|
||||||
|
// This uses custom APIs present on some Samsung devices to allow capture of
|
||||||
|
// meta key events while streaming.
|
||||||
|
try {
|
||||||
|
Class<?> semWindowManager = Class.forName("com.samsung.android.view.SemWindowManager");
|
||||||
|
Method getInstanceMethod = semWindowManager.getMethod("getInstance");
|
||||||
|
Object manager = getInstanceMethod.invoke(null);
|
||||||
|
|
||||||
if (manager != null) {
|
if (manager != null) {
|
||||||
Class<?>[] parameterTypes = new Class<?>[2];
|
Class<?>[] parameterTypes = new Class<?>[2];
|
||||||
parameterTypes[0] = ComponentName.class;
|
parameterTypes[0] = ComponentName.class;
|
||||||
parameterTypes[1] = boolean.class;
|
parameterTypes[1] = boolean.class;
|
||||||
Method requestMetaKeyEventMethod = semWindowManager.getDeclaredMethod("requestMetaKeyEvent", parameterTypes);
|
Method requestMetaKeyEventMethod = semWindowManager.getDeclaredMethod("requestMetaKeyEvent", parameterTypes);
|
||||||
requestMetaKeyEventMethod.invoke(manager, this.getComponentName(), enabled);
|
requestMetaKeyEventMethod.invoke(manager, this.getComponentName(), enabled);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LimeLog.warning("SemWindowManager.getInstance() returned null");
|
||||||
|
}
|
||||||
|
} catch (ClassNotFoundException ignored) {
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
LimeLog.warning("SemWindowManager.getInstance() returned null");
|
|
||||||
}
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user