在程序里设置默认输入法需要怎么实现我自己使用Settings.Secure.putString这个API 但是说写的权限不够代码如下
package zy.setinput;import java.util.List;import android.app.Activity;
import android.content.Context;
import android.os.Bundle;import android.provider.Settings;
import android.util.Log;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;public class setinput extends Activity {
    /** Called when the activity is first created. */
 private List<InputMethodInfo> mInputMethodProperties;
 private String mLastInputMethodId;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        StringBuilder builder = new StringBuilder(256);
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);        mInputMethodProperties = imm.getInputMethodList();
        final InputMethodInfo property = mInputMethodProperties.get(2);
        final String id = property.getId();
        builder.append(id);
        Log.i("id",id);
        mLastInputMethodId = Settings.Secure.getString(getContentResolver(),
            Settings.Secure.DEFAULT_INPUT_METHOD);
        Log.i("mLastInputMethodId",mLastInputMethodId );
      // Settings.Secure.putString(getContentResolver(),
            //    Settings.Secure.ENABLED_INPUT_METHODS, id);
        try
        
        {
        
         Settings.Secure.putString(getContentResolver(),
                    Settings.Secure.ENABLED_INPUT_METHODS, builder.toString());
           Log.i("put","success");
        }catch (Exception ex){
          Log.i("put",ex.toString());
        }
        /*Settings.Secure.putString(getContentResolver(),
                Settings.Secure.DEFAULT_INPUT_METHOD,
                mLastInputMethodId != null ? mLastInputMethodId : "");*/
    }
}我加入了权限
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
但是最后日志还是打印出
 Log.i("put",ex.toString());
07-22 18:50:30.273: INFO/put(18722): java.lang.SecurityException: Cannot write secure settings table
应该是写的secure settings table的权限不够但是源码里面的settings程序也是这么设置输入法的
不知道是什么原因希望各位能指点下~ 不胜感激

解决方案 »

  1.   

    如果是和权限有关系的话,推荐一篇文章。http://blog.csdn.net/yihua0001/archive/2010/06/09/5659665.aspx
      

  2.   

    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />这两个权限我都加了 依然不行
      

  3.   

    http://hi.baidu.com/thenightthemoonthewater/blog/item/3e02103456c1d9305bb5f5eb.html/cmtid/233f473e5e6ca53070cf6cff
      

  4.   

    参照自带的输入法的res/xml/method.xml 文件,把Android:isDefault 值改为true应该就可以了。
      

  5.   

    http://hi.baidu.com/wishwingliao/blog/item/65a2d03f7dde8dd17d1e71ec.html
      

  6.   

    manifest 里加入 android:sharedUserId="android.uid.system"