安卓14 默认比利时物理键盘

客户要求默认键盘

bash 复制代码
+#fi
+
+echo "ro.product.locale=nl-BE"
 echo "ro.wifi.channels=$PRODUCT_DEFAULT_WIFI_CHANNELS"

后面发现usb otg 转接的键盘无法配置成比利时键盘 AZERTY

思路是在监听物理键盘的插入,直接在监听中配置成比利时键盘

bash 复制代码
diff --git a/src/com/android/settings/sim/receivers/SimCompleteBootReceiver.java b/src/com/android/settings/sim/receivers/SimCompleteBootReceiver.java
index e9acf94976..8fc0001aea 100644
--- a/src/com/android/settings/sim/receivers/SimCompleteBootReceiver.java
+++ b/src/com/android/settings/sim/receivers/SimCompleteBootReceiver.java
@@ -21,6 +21,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.util.Log;
 
+import com.android.settings.Junjie;
 import com.android.settings.sim.SimActivationNotifier;
 import com.android.settings.sim.SimNotificationService;
 
@@ -34,6 +35,10 @@ public class SimCompleteBootReceiver extends BroadcastReceiver {
             Log.e(TAG, "Invalid broadcast received.");
             return;
         }
+        Intent i = new Intent(context, Junjie.class);
+        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+        context.startService(i);

在这个开机广播中启动监听服务

bash 复制代码
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 3ec0a3cff0..baee450325 100755
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -189,6 +189,11 @@
                        android:value="true" />
         </activity>
 
+        <service android:name=".Junjie"
+            android:enabled="true"
+            android:exported="true"
+            />
+
bash 复制代码
package com.android.settings;
import android.app.Service;
import android.os.IBinder;
import android.content.Context;
import android.view.InputDevice;
import android.os.Handler;
import android.content.Intent;
import android.os.Message;
import android.content.res.Configuration;
import android.hardware.input.InputManager;
import android.hardware.input.InputDeviceIdentifier;
import android.view.inputmethod.InputMethodManager;

public class Junjie extends Service implements InputManager.InputDeviceListener{
    private InputManager mIm;
    private Context context;
    public void onCreate(){
        super.onCreate();
        context = getApplicationContext();
    }
    @Override
    public void onStart(Intent intent, int startId) {
        // TODO Auto-generated method stub
        super.onStart(intent, startId);
        mIm = (InputManager)context.getSystemService(Context.INPUT_SERVICE);
        mIm.registerInputDeviceListener(this, null);//添加监听
        int[] ids = mIm.getInputDeviceIds();//非常重要, 决定后续是否能监听到状态变化
    }
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        // TODO Auto-generated method stub
        //doNothing
        android.util.Log.d("KeyboardService", "0410 onConfigurationChanged");

    }
    public void onDestroy(){
        super.onDestroy();
        mIm.unregisterInputDeviceListener(this);//注销监听
    }
    public IBinder onBind(android.content.Intent intent){
        return null;
    }
    @Override
    public void onInputDeviceAdded(int deviceId){
        android.util.Log.d("KeyboardService", "0410 > onInputDeviceAdded() deviceId:"+deviceId);
        InputMethodManager input = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);//得到InputMethodManager。
        final int[] devices = InputDevice.getDeviceIds();//获取设备
        for (int i = 0; i < devices.length; i++) {//遍历查找
            InputDevice device = InputDevice.getDevice(devices[i]);
            if (device != null
                    && !device.isVirtual()
                    && device.isFullKeyboard()) {
                InputDeviceIdentifier identifier = device.getIdentifier();
               // mIm.addKeyboardLayoutForInputDevice(identifier,
               //         "com.android.inputdevices/com.android.inputdevices.InputDeviceReceiver/keyboard_layout_belgian");//添加布局
                // liujunjie
                //mIm.setKeyboardLayoutForInputDevice(identifier,
                //        "com.android.inputdevices/com.android.inputdevices.InputDeviceReceiver/keyboard_layout_belgian");//更改布局

                mIm.setKeyboardLayoutForInputDevice(identifier,0,input.getCurrentInputMethodInfo(),input.getCurrentInputMethodSubtype(),
                        "com.android.inputdevices/com.android.inputdevices.InputDeviceReceiver/keyboard_layout_belgian");
            }
        }
    }
    @Override
    public void onInputDeviceRemoved(int deviceId){
        android.util.Log.d("KeyboardService", "0410 > onInputDeviceRemoved() deviceId"+deviceId);
    }

    @Override
    public void onInputDeviceChanged(int deviceId){
        android.util.Log.d("KeyboardService", "0410 > onInputDeviceChanged() deviceID"+deviceId);
    }

}

这个服务的点在于setKeyboardLayoutForInputDevice 4个参数

相关推荐
氦客10 分钟前
Android Compose 图层的合成 : BlendMode
android·compose·jetpack·layer·blendmode·graphics·图层的合成
Sahadev_1 小时前
GitMemo 安卓版发布了:现在可以随时随地查看和记录自己的笔记
android·笔记·创业创新
龙之叶1 小时前
Android 12:在 ActivityStarter 层拦截分享、搜索与 HTTP 外链
android·chrome·http
牛奔2 小时前
Android 开发通用解决方案:使用 ADB 彻底卸载已安装 App(解决版本降级安装失败问题)
android·adb
tryqaaa_2 小时前
学习日志(三)【php语法学习,iscc校赛wp】
android·网络协议·学习·安全·web安全·web
plainGeekDev3 小时前
Kotlin协程面试题:suspend原理都说不清,协程你真会用?
android·面试·kotlin
Kapaseker3 小时前
Android 官方开始拥抱 WebView
android
ujainu小3 小时前
CANN hixl:大模型 PD 分离场景的零拷贝通信库
android·java·缓存
专注VB编程开发20年4 小时前
b4a用VB语言开发安卓APP-图片缩放库ZoomImageView讲解-双指缩放 + 单指拖动核心源码
android·java·前端
恋猫de小郭4 小时前
Dart 大更新,新增语法糖和各种能力,真的难得了
android·前端·flutter