我正在为android创建自定义键盘。在我的键盘按键上,我想要的就是振动,就像android软键盘一样。我甚至提到这个答案enable/disable keyboard sound and vibration programmatically,但我不明白如何使用它。任何人都可以解释如何在我的自定义键盘应用程序中获得此功Android软键盘按键振动
0
A
回答
0
audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
不要忘记在您的Manifest中包含振动。
0
是的,你可以做到这一点,如果你有根访问。它是一个漫长的过程,但你可以这样做:
步骤:1 创建xml文件,名为com.android.inputmethod.latin_preferences.xml
并保存在资产中。使用asset manager
的,你需要
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
此功能将文件拷贝这个文件复制到你的应用程序文件夹(任何地方,您可以访问):
com.android.inputmethod.latin_preferences.xml
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<boolean name="popup_on" value="false" />
<string name="auto_correction_threshold">1</string>
<boolean name="pref_enable_metrics_logging" value="true" />
<boolean name="pref_voice_input_key" value="true" />
<boolean name="pref_key_use_personalized_dicts" value="true" />
<boolean name="pref_key_block_potentially_offensive" value="true" />
<int name="last_shown_emoji_category_id" value="1" />
<boolean name="sound_on" value="false" />
<string name="emoji_recent_keys">[{"Integer":128533}]</string>
<boolean name="auto_cap" value="true" />
<boolean name="show_suggestions" value="true" />
<boolean name="pref_key_use_contacts_dict" value="true" />
<boolean name="next_word_prediction" value="true" />
<boolean name="pref_key_use_double_space_period" value="true" />
<int name="emoji_category_last_typed_id1" value="0" />
<boolean name="vibrate_on" value="true" />
</map>
第2步资产
public static void copyAssets(Context context, String assetPath, String outFilename) {
AssetManager assetManager = context.getAssets();
InputStream in = null;
OutputStream out = null;
try {
in = assetManager.open(assetPath);
File outFile = new File(context.getExternalFilesDir(null), outFilename);
out = new FileOutputStream(outFile);
copyFile(in, out);
} catch (IOException e) {
Log.e(TAG, "Failed to copy asset: " + outFilename, e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
}
}
public static void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
}
步骤3:覆盖系统偏好文件系统路径(destPath)是/data/data/com.android.inputmethod.latin/shared_prefs
public static void copyToSystem(final String sourceFilePath, final String destPath) {
Thread background = new Thread(new Runnable() {
@Override
public void run() {
try {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
//
os.writeBytes("cp -f " + sourceFilePath + " " + destPath + "\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
process.waitFor();
process.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
Log.e(TAG, e.toString());
} catch (IOException e) {
e.printStackTrace();
Log.e(TAG, e.toString());
}
}
});
background.start();
}
步骤4:重启设备
这一切完成。这些步骤将禁用按键声音并启用按键振动设备。
相关问题
- 1. 隐藏android软键盘当软键盘按一键时
- 2. android软键盘按键事件
- 3. 软键盘按钮
- 4. Android的软键盘
- 5. Android动态更改软键盘中的按键
- 6. Android软键盘 - 需要Android软键盘的源代码AOSP
- 7. ANDROID ANDROID:从Android软键盘获取按键
- 8. android - 按需显示软键盘
- 9. Android软键盘操作按钮
- 10. Android软键盘隐藏按钮
- 11. 重命名软键盘上的按键
- 12. 删除0-9按键的软键盘?
- 13. Android - 获取键盘按键
- 14. EditText下的Android软键盘 - 设置软键盘位置
- 15. Android的软键盘键位布局
- 16. Android禁用软键盘输入键
- 17. 中文Android软键盘
- 18. 软输入键盘与Android
- 19. Android软键盘示例
- 20. 与软键盘的Android
- 21. Android软键盘隐藏RecyclerView
- 22. Android软键盘覆盖EditText?
- 23. onClick控制软键盘 - Android
- 24. Android上的软键盘
- 25. Android软键盘问题
- 26. Android软键盘监听器?
- 27. Android软键盘不正常
- 28. android软键盘不显示
- 29. android软键盘事件
- 30. Appcelerator Titanium Android软键盘