在程序里设置默认输入法需要怎么实现我自己使用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程序也是这么设置输入法的
不知道是什么原因希望各位能指点下~ 不胜感激
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程序也是这么设置输入法的
不知道是什么原因希望各位能指点下~ 不胜感激
解决方案 »
- facebook如何获取某一个话题的数据
- 这种布局为什么按下输入框,键盘会把输入框挡住。。
- SimpleAdapter 应用
- Notification 通知栏的图标怎么显示内存卡上面的图片?
- 急!急!!急!!!android edittext 当软键盘开启时,如何监听KeyEvent.KEYCODE_BACK按键?
- 奇怪的include改动无效问题。
- 手机如何能识别图片中的内容呢
- 请问一个在列表控件中有一个倒三角形的那个是什么控件
- 想实现iphone的屏幕触摸旋转和纹理贴图
- 安卓的NDK和SDK能实现的效果相同吗?
- android 4 /data 目录每次都被清空
- 我一运行就报错,大神帮我看看
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />这两个权限我都加了 依然不行