Android 代码设置默认输入法

闲话不多说,直接上代码
import android.app.ActivityManagerNative;
import android.os.UserHandle;
import android.os.RemoteException;
import android.provider.Settings;

String imid = “com.android.inputmethod.latin/.LatinIME”;//输入法的包名
public static void setInputMethod(String imid,Context context) {
int userId;
try {
userId = ActivityManagerNative.getDefault().getCurrentUser().id;
Settings.Secure.putStringForUser(context.getContentResolver(),
Settings.Secure.DEFAULT_INPUT_METHOD, imid, userId);

        if (ActivityManagerNative.isSystemReady()) {
            Intent intent = new Intent(Intent.ACTION_INPUT_METHOD_CHANGED);
            intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
            intent.putExtra("input_method_id", imid);
            context.sendBroadcastAsUser(intent, UserHandle.CURRENT);
        }
    } catch (RemoteException e) {
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果要在 Android ROM 开发中修改默认输入法,可以按照以下步骤进行: 1. 下载 Android 源码,使用 Android Studio 等 IDE 进行编译。 2. 打开源码中的 AndroidManifest.xml 文件,在其中添加以下代码: ``` <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.settings"> <application> <service android:name=".inputmethod.InputMethodAndSubtypeEnabler" android:permission="android.permission.BIND_INPUT_METHOD" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.VOICE_LAUNCH" /> </intent-filter> <meta-data android:name="android.settings.APP_NAME" android:resource="@string/input_method_settings_label" /> <meta-data android:name="android.settings.TOP_LEVEL_SETTINGS" android:value="true" /> </service> </application> </manifest> ``` 这段代码定义了一个名为 InputMethodAndSubtypeEnabler 的服务,用于启用输入法和子类型。其中,android:name 属性指定了服务的名称,android:permission 属性指定了服务需要的权限,android:exported 属性指定服务是否可以被其他应用调用。meta-data 标签用于指定服务的名称和是否为顶级设置。 3. 在 Android 源码中找到输入法应用程序的代码,修改其中的默认设置。 4. 编译源码,并将编译后的系统镜像刷入目标设备。 需要注意的是,修改默认输入法需要具备一定的 Android 系统开发经验,建议在熟悉 Android 开发的前提下进行操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值