Dialog打开和关闭键盘异常问题
/**打开键盘**/
public void openInputFromWindow() {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(mContext.INPUT_METHOD_SERVICE);
imm.showSoftInput(rootView, 0); // 这里需要传入activity的根View
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
/**关闭键盘**/
public void cleanInputFromWindow() {
if (editText != null) {
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}
}
键盘事件执行2次
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if(event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() != KeyEvent.ACTION_DOWN) {//不响应按键抬起时的动作
}
return super.dispatchKeyEvent(event);
}
因为键盘事件会执行ACTION_DOWN和ACTION_UP事件
Cipher加解密
private static byte[] encrypt(byte[] key, byte[] input) throws NoSuchPaddingException,NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(input);
return encrypted;
}
private static byte[] decrypt(byte[] key, byte[] encrypted) throws NoSuchPaddingException,NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] decrypted = cipher.doFinal(encrypted);
return decrypted;
}
判断Root权限
private static boolean isRoot() {
String binaryName = "su";
boolean found = false;
if (!found) {
String[] places = {"/sbin/", "/system/bin/", "/system/xbin/", "/data/local/xbin/","/data/local/bin/", "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/"};
for (String where : places) {
if (new File(where + binaryName).exists()) {
found = true;
break;
}
}
}
return found;
}
TextView默认文字开发时显示运行时隐藏
xmlns:tools="http://schemas.android.com/tools"
tools:text="默认文字"
Hander移除Message或者Runnable
handler.removeCallbacksAndMessages(null);
Android自带工具android.webkit.URLUtil
boolean isUrl= URLUtil.isValidUrl(url);
防止截屏(阅后即焚)
https://juejin.im/post/594fe55d5188250d957612da
规律性动态获取资源文件
http://blog.youkuaiyun.com/jenly121/article/details/51564229