android输入法测试demo

一个简单的输入法测试demo

package com.example.testime;

import java.util.List;

import android.os.Bundle;
import android.provider.Settings;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.Menu;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        
        List<InputMethodInfo> infos = imm.getInputMethodList();
        Log.i("linhui","当前输入法数量:" + infos.size());
        
        String enable = Settings.Secure.getString(getContentResolver(),
                Settings.Secure.ENABLED_INPUT_METHODS);
        
        Log.i("linhui","enable inputmethod:"+enable);
        
        for (InputMethodInfo info : infos)
        {
            Log.i("linhui","输入法包名:" + info.getPackageName());

            int sum = info.getSubtypeCount();
            Log.i("linhui","输入法子类型数量:" + sum);

            for (int i = 0; i < sum; i++)
            {
                // 取得输入法中包含的每一个子类型
                final InputMethodSubtype subtype = info.getSubtypeAt(i);
                // 子类型的语言环境
                final String locale = subtype.getLocale().toString();
                Log.i("linhui","子类型语言环境:  " + locale + "  ,hashcode:"
                        + subtype.hashCode());
            }
        }
     
        
        String currentInputmethod = Settings.Secure.getString(getContentResolver(),
                Settings.Secure.DEFAULT_INPUT_METHOD);
        Log.i("linhui","当前输入法:"+currentInputmethod);
        
        String launge = Settings.Secure.getString(getContentResolver(), Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE);
        Log.i("linhui","当前语言:"+launge);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
}
posted @ 2018-06-14 16:19  mail181  阅读(21)  评论(0编辑  收藏  举报